HyungjinJeon :
How can i select TitledPane`s title in Java Code, without CSS?
I made TitledPane and want to make the title`s font weight is bold.
So i tried like this.
TitledPane Rootpane = new TitledPane();
Rootpane.setText("Options");
Rootpane.setStyle("-fx-background-color: #eeeeee; -fx-text-fill: #1b75bc; -fx-font-weight: bold;");
and the title became bold but the other buttons which are located in TitledPane also became bold...
I just want to make Title is bold without CSS file.
So how can i select the title in Java Code?
And i tried like this
Rootpane.lookup(".titled-pane > .title").setStyle("-fx-font-weight: bold;");
But the result was
Exception in thread "main" java.lang.NullPointerException
Samuel Philipp :
You should call the lookup()
after the node was added to the stage and after Stage.show()
. For example like this:
@Override
public void start(Stage primaryStage) {
TitledPane root = new TitledPane();
root.setText("Options");
primaryStage.setScene(new Scene(root, 200, 100));
primaryStage.show();
root.lookup(".titled-pane > .title > .text").setStyle("-fx-font-weight: bold;");
}
As you can see you should also use .titled-pane > .title > .text
to get the actual text label (docs).