【问题标题】:JavaFx multi lines tab titleJavaFx 多行选项卡标题
【发布时间】:2019-12-04 22:00:23
【问题描述】:

标签窗格标签的标题很长。请帮我制作包含多行的标签标题。

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);
    }
}

【问题讨论】:

  • 插入一个 \n 应该可以解决问题: new Tab("tab1 tab1 tab1 \n tab1 tab1 ");
  • @DmitryKolesnikovich 你是对的。我使用 JFoenix。 JFX TabPane 允许这样做。可悲的是常规不是

标签: javafx


【解决方案1】:

试试这个:

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;
}

【讨论】:

  • 你是怎么做到的?我创建了文件 stylesheet.css 并添加了 line scene.getStylesheets().add("stylesheet.css");但这没有效果
  • 复制Main.javaMain.css,放到同一个目录下运行。
  • 我这样做了,但没有任何效果。你能把你的项目发给我吗?可能是版本问题?
  • 也许这里有人会测试它并发布他/她的结果
猜你喜欢
  • 2016-09-14
  • 1970-01-01
  • 1970-01-01
  • 2017-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多