How to prevent that text in Tabs of TabPane (JavaFX) gets cut off?

Viewed 90

I'm trying to make a simple TabPane with tabs with font-size = 20 in javafx. When I let the font-size on default, everything is fine: 1

When I change the font-size to 20, the underside of letters like p gets cut off: 2

I think that's the case, because a container around it is too small, but I tried changing different components of the TabPane in css (from the substructure of TabPane) but can't get it too work. As you see in the screenshots, I tried to exaggerate the size of the buttons and everything around, so it wouldn't influence the label inside.

Here is the css code I ended with after removing stuff that didn't change anything anyway.

TabPane .headers-region {
    -fx-pref-height: 100;
}


TabPane .tab {
    -fx-pref-height: 100;
    -fx-pref-width: 500;
}

TabPane .tab .tab-label {
    -fx-pref-height: 80;
    -fx-pref-width: 400;
    -fx-alignment: center;
    -fx-font-size: 20;
}

EDIT

Minimum reproducible example (like kleopatra suggested):

Java file:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;

public class Main extends Application {
    
    public void start(Stage stage) throws Exception {
        TabPane tabPane = new TabPane();
        Tab tab1 = new Tab("Board");
        Tab tab2 = new Tab("Claims and assumptions");
        tabPane.getTabs().addAll(tab1, tab2);
        Scene scene = new Scene(tabPane);
        scene.getStylesheets().add("Path to the css file");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

CSS file:

TabPane .tab-label {
    -fx-font-size: 20;
}
0 Answers
Related