Oracle recommendations
See Oracle tip:
Oracle recommends FXML for layout definition by Java API.
Alternative declarative technologies for JavaFX
Other declarative parts in JavaFX are CSS and 3D models.
The semi-invariant method is the JavaFX Builder API , but you can avoid this as the api builder will be deprecated in future versions of JavaFX .
In addition, if you program in other languages, some of them embed declarative domain language (DSL) for JavaFX development (for example, ScalaFX or GroovyFX ).
In general, the use of declarative syntax has largely benefited from procedural programming for most user interface markup tasks. This can be seen from technologies such as HTML, CSS, FXML, XAML, MXML, XUL, etc.
Low level programming
For low-level tasks, such as developing a custom JavaFX control, manipulating a JavaFX canvas, or processing image data, the procedural Java API is better than using declarative FXML β none of the JavaFX codebase in openjfx uses FXML.
Personal choices and tips
In the end, there is no right answer. The choice is up to the developer to choose the approach that they like best.
There is also no reason why you cannot mix the two styles on your own. Using a direct declarative approach leaves you with a very tough user interface (like a static html page) compared to mixing both procedural and declarative approaches (like html + javascript + ajax) - and the same is true for JavaFX, since it is for html development in this case.
For small programs, I like to just write some code in the IDE, compile and run it, without having to deal with the context switch between the FXML XML interface and the Java code. But I found that this procedural approach does not just scale well for large projects. Having a view divided into FXML helps ensure separation of problems and modulation. It is too easy to mix these views and logic without the artificial separation that FXML requires.
I don't like XML as an interface layout language. I think that now the nonexistent FXD format from the legacy JavaFX 1.x branch was much higher. However, FXML is the most accessible and widely used declarative user interface syntax for JavaFX 2.
I often use CSS with JavaFX programs and like to use it with both the conditional code FXML and the procedural code Java API. In my opinion, it is at least as important to separate the style from the code, since it is intended for layout layout from the code.
When using CSS, itβs always better to put your styles in a separate stylesheet rather than embed styles in your code.
As already mentioned in another answer, the JavaFX SceneBuilder visual design tool currently only works with FXML and, among other things, is a good reason for many to use FXML to define their JavaFX interface.