javajavafx

JavaFX TitledPane: Remove Title


is it possible to completely remove the title of a TitledPane?

I managed to make it invisible using the following code in the css-file:

.titled-pane > .title{
    -fx-background-color: rgba(0, 100, 0, 0.0);
    -fx-font-size: 0;
}

But it still takes up space, and when I hover over it with my mouse, the cursor changes. Changing the padding didn't help either.

Basically, I only need the expandable / collapsable abilities of the TitledPane, which are executed when a Button is pressed.


Solution

  • According to the TitledPane's Substructure, the title is a HBox. So we can lookup it and hide then:

    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            Pane title = (Pane) titledPane.lookup(".title");
            if (title != null) {
                title.setVisible(false);
            }
        }
    });
    

    It should be run in Platform.runLater(...) after the scene constructed and rendered.