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

I recently discussed CSS with JavaFX and noticed that I used the same style several times in my node's stylesheet.

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

Example:

application.css

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

      

Main.java

public class Main extends Application {
    @Override
    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);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(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 style used will always be the last one in the css file, i.e. e. "BG-color-2".

Question

Why is List used instead of Set?

+3


source to share


1 answer


This is the css standard. Your root object contains both style classes.

Css-Parser or Render or IDK (the thing that convinces css) reads the CSS file from top to bottom.



This means it changes the Backgroundcolor to red, not green.

so if you remove "bg-color-2" from the root it will be red otherwise it will be green.

0


source







All Articles