简体   繁体   English

在 JavaFX 中更改 TabPane 的 Tab 大小

[英]Change Tab's Size of TabPane in JavaFX

Can we change the tab's size of TabPane in JavaFX?我们可以在 JavaFX 中更改 TabPane 的选项卡大小吗? I am using SceneBuilder but it seems it doesn't offer any customozation of the tab's size我正在使用 SceneBuilder,但它似乎不提供选项卡大小的任何自定义

Currently I have something like this目前我有这样的事情

. .

What I want is basically the tabs to fill the parent and when it is clicked it will show the other forms like this (I made it with button as only the rough image)我想要的基本上是填充父级的选项卡,当它被点击时,它会显示像这样的其他表单(我用按钮制作的只是粗略的图像)

在此处输入图片说明

Is it possible to do something like this?有可能做这样的事情吗? Any help is appreciated.任何帮助表示赞赏。 Thanks谢谢

As far as I know the width and height of elements are read-only.据我所知,元素的宽度和高度是只读的。 You can set -fx-pref-width, -fx-pref-height, -fx-max-width, -fx-min-width, -fx-max-height, -fx-min-height ,-fx-border-width and -fx-border-height to adjust the size of Java FX elements.您可以设置 -fx-pref-width、-fx-pref-height、-fx-max-width、-fx-min-width、-fx-max-height、-fx-min-height、-fx-border- width 和 -fx-border-height 来调整 Java FX 元素的大小。

You can do what you want by using Css:你可以使用 Css 做你想做的事:

.tab {

    -fx-pref-width: 250
} 
.tab-header-background {
    -fx-background-color:transparent
}

.tab-pane{
    -fx-padding: 0 -1 -1 -1
}

在此处输入图片说明

We can set minimum/maximum width/height for all Tabs on TabPane.我们可以为 TabPane 上的所有选项卡设置最小/最大宽度/高度。

@FXML
TabPane tabPane;

and somewhere:和某处:

tabPane.setTabMinWidth(33);
tabPane.setTabMinHeight(33);
tabPane.setTabMaxWidth(69);
tabPane.setTabMaxHeight(69);

You can acheieve this with property binding:您可以通过属性绑定来实现这一点:

val binding = tabPaneParent.widthProperty().doubleBinding(tabPane.tabs) {
    it as Double / tabPane.tabs.size // - 30
}

tabPane.tabMinWidthProperty().bind(binding)
tabPane.tabMaxWidthProperty().bind(binding)

tabPaneParent is the Node in which tabPane lives, doubleBinding is TornadoFX's equivlant of Bindings#createDoubleBinding . tabPaneParent是在节点tabPane生活, doubleBinding是TornadoFX的equivlant Bindings#createDoubleBinding

This will react to the user resizing your window, as well as, the tabs count increasing/decreasing.这将对用户调整窗口大小以及选项卡计数增加/减少做出反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM