14

I have a TabPane with several Tabs. If the results of an operation in the Tab failed, I want to set the Tab Label to a Fill red or perhaps the texture to hashed (for those with color blindness). I want to reset the Color back to its default, later.

From reading some of the questions here, one can statically set it using a style sheet.

#MyTabPane .tab *.tab-label {
    -fx-text-fill: white;
}

How would one access the Tab label and set it's color/texture dynamically?

tab.setStyle("??");

ADDITIONS BY ELLTZ

How can one use inline Styles stated above to change the Paint of both the Label with style class tab-label and the Button(StackPane) also tab-close-button

code examples needed

1 Answer 1

25

Setting the graphics and styling it did the trick for me:

Tab tabB = new Tab();
tabB.setText("");
tabPane.getTabs().add(tabB);
tabB.setStyle("-fx-border-color:red; -fx-background-color: blue;");
tabB.setGraphic(new Label("Tab B"));
tabB.getGraphic().setStyle("-fx-text-fill: #c4d8de;");
3
  • 1
    Thanks. Surprisingly, if you do tab1.setGraphic(imageView), and then tab2.setGraphic(imageView), the graphic switches from tab1 to tab2. Only one tab has the graphic.
    – likejudo
    Feb 21, 2013 at 22:18
  • 1
    This is not surprisingly, because a Node can always be only once in the SceneGraph. A "graphic" is a generic Node in the SceneGraph like any Node.
    – zhujik
    Feb 25, 2013 at 15:47
  • 1
    which makes you wonder why they call it a 'graph' in the first place. But well, yes it is a true, so it is not surprising that the ImageView can only have 1 parent.
    – user458577
    Jan 5, 2016 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.