4

Is there a specific document naming convention I should follow when creating FXML files or XML files in general? I've been following some tutorials that Oracle has provided and come to the conclusion that FXML files should start with the prefix

fxml

and end with the suffix

view

So an example FXML document would look like

fxml_tableview.fxml

Tutorial source: http://docs.oracle.com/javafx/2/fxml_get_started/jfxpub-fxml_get_started.htm Specific page: http://docs.oracle.com/javafx/2/fxml_get_started/fxml_tutorial_intermediate.htm

Pavan P
  • 645
  • 8
  • 17
  • 6
    Which tutorials are you referring to? e(fx)clipse demands that FXML filenames begin with a capital letter (like class names). [afterburner.fx](https://github.com/AdamBien/afterburner.fx/) is a framework using a convention-over-configuration approach that relies on filenames like `example.fxml`, `ExampleView.java`, `ExamplePresenter.java` and, optionally, `example.css`. I don't think there's any particularly standardized approach for general JavaFX applications. – James_D Feb 16 '15 at 18:22
  • 5
    Thanks for linking the tutorials. I had seen those tutorials, but hadn't paid particular attention to the filenames. I don't think that style is widely used; the `fxml_` prefix seems particularly redundant. – James_D Feb 16 '15 at 19:01
  • 3
    As the author of e(fx)clipse to me following the Java classnameing convention felt natural but i don't think there is a common rule – tomsontom Feb 16 '15 at 19:05

2 Answers2

5

The CERN paper on JavaFX includes a section on naming conventions.

Both, the FXML file and its controller should have names allowing an easy identification that they belong to the same view, without looking at their content. In fact, JavaFX introduced a naming convention for nested controllers. For instance, if an included view ID is dialog, then the corresponding controller can be referenced as dialogController. This convention could be extended to other entities associated with a single view such as model, service, CSS or resource bundle properties file. In addition, all files related to a single view could be placed in a dedicated Java package, named after the view. In such case the content of every package would be similar:

• [view_name].fxml

• [view_name]Controller.java

• [view_name]Model.java

• [view_name]Service.java

• [view_name].css

• [view_name].properties

Note that only the FXML, controller and in most cases also model files are be present, while CSS, resource bundle and any additional files are optional. Such convention is very easy to remember. With a glimpse of an eye one can recognize all the elements and have a good idea what is inside.

Source: Best Practices For Efficient Development Of JavaFX Applications

qwerty
  • 810
  • 1
  • 9
  • 26
3

I just blogged about the naming conventions I can recommend:

If "mypackage.<name>.java" loads a FXML file, then the FXML file should be in the same package and be named "<name>.fxml".

One advantage is, that when following this naming convention it's quite easy to see, which FXML loader/ fx:root-controller and FXML file belong together.

Another advantage is, that the loading code can be simplified.

You can read more about it here: http://puces-blog.blogspot.ch/2015/03/drombler-commons-conventions-to.html

Puce
  • 37,247
  • 13
  • 80
  • 152