JavaFX CSS:如何设置tabpane选项卡 - 宽度,高度

Mar*_*ers 5 user-interface javafx

我正在尝试制作具有最小宽度和高度的标签,用于触摸屏上的手指大小,而不是内部文本的大小.

.tab-pane *.tab-header-area *.tab-header-background {
  -fx-background-color:transparent;
  -fx-tab-min-width:120px;
  -fx-tab-max-width:120px;
  -fx-tab-min-height:50px;
  -fx-tab-max-height:50px;
}

.tab {
  -fx-font-family: Arial;
  -fx-font-size: 18;
  -fx-background-color:royalblue ;
}

.tab:selected {
    -fx-background-color:blue ;
}
Run Code Online (Sandbox Code Playgroud)

颜色和字体都有效,但尺寸无效.我尝试了许多尺寸,使用px和em,但没有效果.

    TabPane tabPane = new TabPane();

    Tab tab1 = new Tab();
    tab1.setText("Machine");
    tab1.setClosable(false);

    Tab tab2 = new Tab();
    tab2.setText("Shifts");
    tab2.setClosable(false);

    tabPane.getTabs().addAll(tab1, tab2);
Run Code Online (Sandbox Code Playgroud)

Jam*_*s_D 12

你想设置的大小属性的属性TabPane.

您使用的选择器:

.tab-pane *.tab-header-area *.tab-header-background
Run Code Online (Sandbox Code Playgroud)

选择选项卡窗格的选项卡标题区域子项的选项卡标题背景子项:即a StackPane(请参阅上面链接的文档的"子结构"部分).StackPane没有定义那些属性,因此在CSS中它们没有任何效果.

直接在选项卡窗格上设置大小属性:

.tab-pane *.tab-header-area *.tab-header-background {
  -fx-background-color:transparent;
}

.tab-pane {
  -fx-tab-min-width:120px;
  -fx-tab-max-width:120px;
  -fx-tab-min-height:50px;
  -fx-tab-max-height:50px;
}

.tab {
  -fx-font-family: Arial;
  -fx-font-size: 18;
  -fx-background-color:royalblue ;
}

.tab:selected {
    -fx-background-color:blue ;
}
Run Code Online (Sandbox Code Playgroud)