ComboBoxes

Associating With An Enum

One of the tidiest ways of populating a JavaFX ComboBox is to associate it with an enumeration. The enumeration defines the objects you can select from in the ComboBox, as well as how to display these objects (their String representations).

First, we need to create an enum:

Then, to populate the  ComboBox, just type:

To select an item from code (useful for say, setting the default value of the  ComboBox ), type:

Notice we are now dealing with objects, rather than having to parse strings!