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
Notice we are now dealing with objects, rather than having to parse strings!
This work is licensed under a Creative Commons Attribution 4.0 International License .