Sunday 15 May 2011

java - How to get components from an AnchorPane in JavaFX -



java - How to get components from an AnchorPane in JavaFX -

my problem this. need validate form, , i've done css styles , need. wonder if have way form components through anchorpane.

is there way can component of anchorpane fx: id?

using fxml controller fellow member references

probably best solution given using fxml, create utilize of reference node injected in controller. when have fx:id element, have corresponding fellow member in fxml @fxml annotation. can utilize mechanisms defined in passing parameters javafx fxml reference controller. controller can either straight expose node via getter or (usually better), expose properties representing state of node (e.g. text of label) , can hear , manipulate properties if necessary.

using getchildren on pane

you can phone call pane.getchildren() children of pane, additionally recursively calling getchildren on each of children if needed. sophisticated solution can utilize visitor pattern.

using css lookups

as have set css styles, rather iterating through children, can utilize css lookup look kid css id. note have define id attribute nodes in add-on fx:id attribute in order such lookups work. note css must have been applied nodes work, e.g. nodes shown (already displayed) on active scene, or have manually triggered applycss() function parent node (when attached scene). these additional constraints , non-typed, non-compiler verified nature of css selectors, makes using css lookups mechanism finding children pretty fragile solution , recommended in limited circumstances.

given task form validation, might want google javafx form validation , take existing library rather trying roll own thing. illustration libraries might consider jidefx, fxform2 or controlsfx.

java validation javafx

No comments:

Post a Comment