我的 fxml 文件上有多个按钮。onAction通过单击任何按钮,将显示定义的 fxml 表单。问题是:
我是否应该使用例如 foreach 加载所有表单,并且当按钮单击正确的表单时仅显示或没有必要?
如果我应该加载所有表单,我应该在initialize函数中执行它吗?
我是新手JavaFx,不知道最好的方法是什么?
编辑:
例如,当 btn1 单击时,将显示“添加用户”表单,当单击“btn2”时,将显示“删除用户”表单,...
问题是:
我是否应该加载添加用户表单并删除用户表单,...当程序启动时以及当例如 btn1 单击添加用户表单时是否显示?
<BorderPane fx:controller="com.project.controller.eventcontroller" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<left>
<VBox prefHeight="400.0" prefWidth="110.0" style="-fx-background-color: #404040;" BorderPane.alignment="CENTER">
<children>
<Button fx:id="btn1" alignment="TOP_LEFT" mnemonicParsing="false" prefHeight="17.0" prefWidth="111.0" text="btn1" />
<Button fx:id="btn2" alignment="TOP_LEFT" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" prefHeight="17.0" prefWidth="111.0" text="btn2">
<VBox.margin>
<Insets top="12.0" />
</VBox.margin>
</Button>
<Button fx:id="btn3" alignment="TOP_LEFT" layoutX="10.0" layoutY="47.0" mnemonicParsing="false" prefHeight="17.0" prefWidth="111.0" text="btn3">
<VBox.margin>
<Insets top="12.0" />
</VBox.margin> …Run Code Online (Sandbox Code Playgroud)