FXML Best Practices

Richard Bair richard.bair at oracle.com
Wed Dec 19 19:40:33 PST 2012

> The second reason however is that Richard used SceneBuilder to create his
> FXML and it makes me think that SB might be biased towards the first
> pattern (?). Does SB integrate with Controller code and do smarts around
> that, or does it leave the whole Controller bit out of the equation?

No, SceneBuilder is definitely not optimized for the way I did it. You can specify a controller in SB and it wires everything up. In fact, SB prefers having a Controller because then it can auto-fill the code dialogs with methods you've annotated with @FXML.

The way I coded it up is basically JQuery. It has a heck of a lot less "magic" to it, which is nice. There are a lot of ways to approach the problem, and many of them have merit.

	- In both approaches there is a coupling between the Java file and the XML file that you have to maintain
		- In one approach you have to use @FXML and name the variable the same as the fx:id in the FXML file
		- In the other approach you hard code the id in the Java file and omit the fx:id entirely
	- In one approach you are the extractor, in the other an engine is the extractor. In both cases you're extracting nodes
	- One approach works when in a Security Manager and the other doesn't. Unless you make your annotated fields public.
	- One approach is tool able, the other isn't.

I don't think this really merits a discussion. I was lazy. I think I'm entitled to being lazy :-)


More information about the openjfx-dev mailing list