I need to set CSS Id on Tab at run-time, but ot seems like it doesn't work.
I can set Id before stage is shown, but after that tab remains previous style.
public void start(Stage primaryStage) throws Exception {
TabPane tabPane = new TabPane();
Tab first = new Tab("I'm red");
first.setId("red");
first.setClosable(false);
Tab second = new Tab("I wanna be red");
second.setClosable(false);
Button button = new Button("Make it red");
button.setOnAction( e-> {
second.setId("red");
button.setId("red");
});
second.setContent(button);
tabPane.getTabs().addAll(first, second);
Scene scene = new Scene(tabPane);
scene.getStylesheets().add("Example.css");
primaryStage.setScene(scene);
primaryStage.show();
}
Example.css:
#red {
-fx-background-color: red;
}
I can set Id before stage is shown, but after that tab remains previous style.
public void start(Stage primaryStage) throws Exception {
TabPane tabPane = new TabPane();
Tab first = new Tab("I'm red");
first.setId("red");
first.setClosable(false);
Tab second = new Tab("I wanna be red");
second.setClosable(false);
Button button = new Button("Make it red");
button.setOnAction( e-> {
second.setId("red");
button.setId("red");
});
second.setContent(button);
tabPane.getTabs().addAll(first, second);
Scene scene = new Scene(tabPane);
scene.getStylesheets().add("Example.css");
primaryStage.setScene(scene);
primaryStage.show();
}
Example.css:
#red {
-fx-background-color: red;
}
- duplicates
-
JDK-8186333 TabContentArea bounces for deviant alignment
-
- Closed
-
- relates to
-
JDK-8284329 Weird corners in Tab headers in JavaFX
-
- Open
-