【问题标题】:JavaFX Menu and gridpane controlJavaFX 菜单和网格窗格控件
【发布时间】:2021-03-27 01:57:45
【问题描述】:

Picture of my application now

我希望菜单栏中的“工具”可以对齐,但我在互联网上搜索了很多,但找不到任何有用的东西,所以我在这里尝试。我想要修复但没有找到的下一件事是 Gridpane,它没有填充其父级的大小。如果你们中的任何人知道实现这一点的属性或代码。告诉我!

  public MyMenuBar(StackPane root) {
menu1 = new Menu("KunstwerkLijst");
  menuItem1 = new MenuItem("Lijst van kunstwerken");
    menuItem1.setOnAction(event ->{
         root.getChildren().clear();
         new Home(root);
    });

        menu2 = new Menu("Tools");

  menuItem2 = new MenuItem("Admin Panel");
   menuItem2.setOnAction(event ->{
        root.getChildren().clear();

     //   new APanel(root);
    });

    menu1.getItems().addAll(menuItem1, menuItem4, menuItem6, menuItem5);
    menu2.getItems().addAll(menuItem2, menuItem3);

    this.getMenus().add(menu1);
    this.getMenus().add(menu2);

【问题讨论】:

标签: javafx


【解决方案1】:

Right align menu in menubar in JavaFX

这应该可以帮助您解决第一个问题。如果没有,您可以用工具栏替换菜单栏并执行以下操作:

How to right align a button in Java FX toolbar

对于您的第二个问题,这取决于 Gridpane 的实际父级是什么。
使用 AnchorPane 作为父级是这里最简单的解决方案,然后像这样使用它:

<AnchorPane fx:id="parent">
  <GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
                    AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
    ...
  </GridPane>
</AnchorPane>

【讨论】:

    猜你喜欢
    • 2019-03-27
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 2017-06-23
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    相关资源
    最近更新 更多