Search code examples
javacsssyntaxjavafxstylesheet

What CSS syntax do I need to use to access the Label of a TitledPane in JavaFX?


I don't really know a lot about CSS in the context of JavaFX. I'm trying to access the Labels of some TitledPanes so I can put a simple image next to the Label but I can't figure out what the proper syntax is to do so.

I've tried:

.TitledPane > .title > .text { //TitledPane is the CSS class I assign to my Title Panes.
    /*CSS Code Here*/
}

That didn't work.

.TitledPane > .title { } //This only affects the background, I would like the graphic to be side-by-side with the actual text.

.TitlePane LabeledText { } //This worked with Buttons so I thought it might work with TitledPane. I was wrong.

What do I need to use to access the Label to be able to style it with CSS?


Solution

  • The CSS documentation for TitledPane appears to be wrong: the text class in the title actual resolves to a Text object, not a Label, as stated. Of course, Text does not support an -fx-graphic css property.

    Fortunately, since TitledPane extends Labeled, you can just use the property defined in Labeled directly:

    .TitledPane {
      -fx-graphic: url(path/to/image/file) ;
    }