Learn how to create interfaces with FXML and JAVAFX, factory objects

More on creating objects in FXML. Sometimes, you need to create JavaFX collections in FXML. The FXCollections class contains several factory methods that are used to create these collections.

The FXFactory attribute is another means of creating objects whose classes do not have a default constructor. The value of the attribute is the name of a static, no argument factory method for producing class instances.

Let’s take a look at a simple example in NetBeans. In this FXML file I am using the FXCollections called observable array list, to create an array list that contains an object for each day of the week. It’ll put those objects into a list view. Let’s go ahead and run this.

And you’ll see that it lists out each of the days of the week using the string objects created using the JAVAFX collections.

So now, you have three ways to create objects in FXML. If the class has a no argument constructor, you can just identify the name of the class. Such as, on line 14 here where we have vbox. The second way was using the value of.

Leave a Reply

Notify of