【问题标题】:JavaFX CSS: How to set tabpane tabs - width, heightJavaFX CSS:如何设置 tabpane 选项卡 - 宽度、高度
【发布时间】:2018-04-03 17:11:41
【问题描述】:

我正在尝试制作具有最小宽度和高度的选项卡,用于触摸屏上的手指大小,而不是其中文本的大小。

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

颜色和字体正常,但大小无效。我尝试了多种尺寸,使用 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);

【问题讨论】:

  • 你导入样式表了吗?
  • 是的,对于场景。正如我所说,我得到的是字体和颜色,而不是大小。

标签: user-interface javafx


【解决方案1】:

您尝试设置的尺寸属性是properties of the TabPane

你使用的选择器:

.tab-pane *.tab-header-area *.tab-header-background

选择选项卡窗格的选项卡标题区域子项的选项卡标题背景子项:即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 ;
}

【讨论】:

    猜你喜欢
    • 2011-10-17
    • 2020-03-03
    • 2019-07-07
    • 2014-02-11
    • 2011-08-24
    • 1970-01-01
    • 2015-08-27
    • 2014-07-16
    相关资源
    最近更新 更多