我初始化了一些元素而不是我的Anchor窗格:
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load(), menuLoader.load(), buttonLoader.load());
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试单击MenuBar或列表视图时,它不起作用.例如,在这种情况下,我可以单击按钮(可能),因为它是我在AnchorPane构造函数中初始化的最后一个元素.我无法使用BorderPane或任何其他布局,因此我需要找到具有此配置的解决方案.这些是我的fxml文件:
list.fxml
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">
<children>
<AnchorPane>
<children>
<ListView fx:id="listView" layoutX="1.0" layoutY="31.0" prefHeight="371.0" prefWidth="239.0" />
</children>
</AnchorPane>
</children>
Run Code Online (Sandbox Code Playgroud)
menuBar.fxml
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.MenuBarController">
<children>
<AnchorPane>
<children>
<MenuBar fx:id="menuBar" layoutX="0.0" layoutY="0.0">
<menus>
<Menu text="File">
<items>
<MenuItem onAction="#elimina" text="Elimina" />
</items>
</Menu>
<Menu text="Cambia Account">
<items>
<MenuItem fx:id="email1" text="filippo@hotmail.it" />
<MenuItem fx:id="email2" text="giancarlo@yahoo.it" />
<MenuItem fx:id="email3" text="alessandro@gmail.it" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</AnchorPane>
</children>
Run Code Online (Sandbox Code Playgroud)
textArea.fxml
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.TextAreaController">
<children> …Run Code Online (Sandbox Code Playgroud)