如何通过javafx(选项卡窗格,menebutton)将一些具有不同默认布局的UI集成在一起?



如图所示:我使用Scene Builder在BorderPane Top中创建了一个HBox。 HBox包括两种类型的UI:MenuButton和tabpane。

图片 1

当前的样式是:当我单击选项卡窗格时,选项卡窗格将在菜单按钮下留下一个空白区域,该区域在HBox中未使用。

图片 2

我的要求是什么:当我单击选项卡窗格时,选项卡窗格可以使用此区域。 我找到一个很好的例子:EXCEL。 请参阅 EXCEL 的菜单栏。 "文件"与我的菜单按钮相似(也有一些区别,excel"文件"在单击它时显示一个窗格,我的菜单按钮显示菜单列表(, 和"开始","插图"与我的标签窗格相似。 如果我解释不清楚,请参考一个EXCEL,WORD我们的前景。 谢谢。

我该如何解决这个问题?

  1. 我应该自定义选项卡窗格或菜单按钮的 UI 吗?
  2. 如果有其他 UI 可以实现这一点,我只是不知道? 非常感谢。

在你的FXMLController中试试这个:

// Tells the HBox to expand the tabPane whenever possible.
HBox.setHgrow(tabPane, Priority.ALWAYS);
// If invisible, menuButton will not take space on the screen
menuButton.managedProperty().bind(menuButton.visibleProperty());
// A click on the tabPane will make menuButton invisible, freeing room for the tabPane to take over the rest of the HBox
tabPane.setOnMouseClicked(event -> menuButton.setVisible(false));

最新更新