1

I have long titles for tab pane tabs. Please, help me to make tabs titles to contain more than one line.

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Stage stage = new Stage();

        Tab tab1 = new Tab("tab1 tab1 tab1 tab1 tab1 ");
        Tab tab2 = new Tab("tab2 tab2 tab2 tab2 tab2 ");
        Tab tab3 = new Tab("tab3 tab3 tab3 tab3 tab3 ");
        TabPane tabPane = new TabPane(tab1, tab2, tab3);

        tabPane.setMinHeight(80);
        tabPane.setMaxWidth(230);

        HBox hbox = new HBox(10);
        hbox.getChildren().addAll(new Label("Tabs ==> "), tabPane);

        Scene choosePlayer = new Scene(hbox, 300, 400);
        stage.setScene(choosePlayer);
        stage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}
Tom
  • 2,734
  • 2
  • 22
  • 39
Vadim S
  • 11
  • 1

1 Answers1

0

Try this :

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

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Stage stage = new Stage();

        Tab tab1 = new Tab("tab1 tab1 tab1\ntab1 tab1");
        Tab tab2 = new Tab("tab2 tab2 tab2\ntab2 tab2 ");
        Tab tab3 = new Tab("tab3 tab3 tab3\ntab3 tab3 ");
        TabPane tabPane = new TabPane(tab1, tab2, tab3);

        HBox hbox = new HBox(10);
        hbox.getStylesheets().add(getClass().getResource("Main.css").toExternalForm());
        hbox.getChildren().addAll(tabPane);

        Scene choosePlayer = new Scene(hbox);
        stage.setScene(choosePlayer);
        stage.show();
    }

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

Main.css

.tab-pane {
    -fx-tab-min-height: 70;
    -fx-tab-max-height: 70;
}

enter image description here

c0der
  • 18,467
  • 6
  • 33
  • 65