I am building an input form in JavaFx from Java 8.0 using SceneBuilder 2.0 on Windows 7 in e(fx)clipse.
I have a simple String ComboBox, and want to change the color and size of the fonts in both the list and the selected String. The css code I use changes the text on the selected item. However, the first time one drops the list, it is in black default font. The second time, the font color and size on all items have changed to the correct values.
How do I make the font list start up in the right color and size?
Here is simplified code from the initialize method in my Controller class:
ObservableList<String> types = FXCollections.observableArrayList
( "large", "medium", "small" );
comboBox.setItems( types );
and current css:
#comboBox .list-cell
{
-fx-font-family: arial;
-fx-font-size: 16px;
-fx-text-fill: #a0522d;
}
You have to create a CellFactory and you can't use CSS ( I don't know why but it's the only way I could get it to work):
Despite of the fact that you are using the standard API, I believe that you also should use it in the
CSS
and specify in theCSS
that the first time have to be set programmatically as this will be useful for whoever will maintain your software.style.css
The curious detail: for JavaFX 2 you could set this via
CSS
but still had to use a CellFactory.