Why are style classes stored in a List instead of a Set?

Roland C roland.cidar at gmail.com
Thu May 21 05:17:15 UTC 2015

I was recently toying around with CSS in JavaFX and noticed that I got the
same style multiple times in the style list of my node.

Since the order of the styles is defined by the order in the css file and
not by the order of the list that getStyleClass() of a node returns, I was
wondering if there is a special reason for that.



.bg-color-1 {
    -fx-background-color:red; }.bg-color-2 {


public class Main extends Application {
    public void start(Stage primaryStage) {
        try {
            BorderPane root = new BorderPane();

            root.getStyleClass().add( "bg-color-1");
            root.getStyleClass().add( "bg-color-2");

            Scene scene = new Scene(root,400,400);
        } catch(Exception e) {

    public static void main(String[] args) {

It doesn't matter if you write

    root.getStyleClass().add( "bg-color-1");
    root.getStyleClass().add( "bg-color-2");

or change the order to

    root.getStyleClass().add( "bg-color-2");
    root.getStyleClass().add( "bg-color-1");

The used style will always be the last in the css file, i. e. "bg-color-2".


Why is a List used instead of a Set? A list is less performing than a Set
and it clutters the code if you always have to make a contains-check first.

Thank you very much!

More information about the openjfx-dev mailing list