Css – JavaFX Tab fit full size of header

cssjavafxsizetabs

I want the tabs in my tabpane to fit the complete size of the tabpane which they are in. So basically there shall be no header area visible, everything should be covered by the tabs.

I have 2 problems here:

  • How can I make the tabs dynamically fit the width of the tabpane?
  • How can I fit them to the correct height, and remove the little spaces between the tabs? I suppose this is done via css, but I don't quite know how.

greets

Best Answer

You can simply add a listener to the TabPane to detect any changes and adjust the width and/or height of the tabs accordingly.

@FXML
private JFXTabPane tabPane;

Divide the width by number of tabs:

tabPane.widthProperty().addListener((observable, oldValue, newValue) ->
    {
        tabPane.setTabMinWidth(tabPane.getWidth() / tabPane.getTabs().size());
        tabPane.setTabMaxWidth(tabPane.getWidth() / tabPane.getTabs().size());      
    });
Related Topic