[英]Change Tab's Size of TabPane in JavaFX
據我所知,元素的寬度和高度是只讀的。 您可以設置 -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 元素的大小。
你可以使用 Css 做你想做的事:
.tab {
-fx-pref-width: 250
}
.tab-header-background {
-fx-background-color:transparent
}
.tab-pane{
-fx-padding: 0 -1 -1 -1
}
我們可以為 TabPane 上的所有選項卡設置最小/最大寬度/高度。
@FXML
TabPane tabPane;
和某處:
tabPane.setTabMinWidth(33);
tabPane.setTabMinHeight(33);
tabPane.setTabMaxWidth(69);
tabPane.setTabMaxHeight(69);
您可以通過屬性綁定來實現這一點:
val binding = tabPaneParent.widthProperty().doubleBinding(tabPane.tabs) {
it as Double / tabPane.tabs.size // - 30
}
tabPane.tabMinWidthProperty().bind(binding)
tabPane.tabMaxWidthProperty().bind(binding)
tabPaneParent
是在節點tabPane
生活, doubleBinding
是TornadoFX的equivlant Bindings#createDoubleBinding
。
這將對用戶調整窗口大小以及選項卡計數增加/減少做出反應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.