我正在编写一个具有 2 个不同 BorderPane、BorderPane A 和 BorderPane B 的应用程序。该应用程序有 2 个菜单项,因此,当单击它时,它必须显示 BorderPane A 或 BorderPane B。
这是 Application 类,它有我想要使用的阶段
public class SampleApp extends Application {
private Stage primaryStage;
public static void main(final String[] args) {
launch(args);
}
@Override
public void start(final Stage stage)
throws Exception {
final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleAppFactory.class);
final SpringFxmlLoader loader = new SpringFxmlLoader(context);
final Parent root = (Parent) loader.load("Main.fxml", Main.class);
final Scene scene = new Scene(root, 600, 480, Color.ALICEBLUE);
this.primaryStage = stage;
scene.getStylesheets().add("fxmlapp.css");
stage.setScene(scene);
stage.show();
}
}
The Main.java Class has two BorderPanes, when the menuItem is chosen I want to show the borderpane on the Application.
有人知道如何通过这种方法(showBorderPane)显示 Borderpane(在舞台上设置场景)吗?我想检索舞台并使用 deborderpane 设置场景:
public class Main extends BorderPane implements Initializable {
@FXML
private Verbinding verbindingContent; // BORDERPANE A
@FXML
private Beheer beheerContent;// BORDERPANE A
@FXML
private MenuBar menuContent;
@Override
public void initialize(final URL url, final ResourceBundle rb) {
System.out.println(url);
menuContent.setFocusTraversable(true);
}
@FXML
private void showBorderPane(final ActionEvent event) {
final MenuItem menuItem = (MenuItem) event.getSource();
}
@FXML
private void handleCloseAction(final ActionEvent event) {
System.exit(0);
}
}
我的 Main.xml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.effect.*?>
<?import nl.mamaloe.tab.view.Main?>
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="nl.mamaloe.tab.view.Main">
<fx:define>
<fx:include source="scene/Beheer.fxml" fx:id="beheerContent" />
<!-- fx:include source="Menu.fxml" fx:id="menuContent" / -->
</fx:define>
<top>
<MenuBar fx:id="menuContent" onMouseClicked="#handleKeyInput">
<menus>
<Menu text="Systeem">
<items>
<MenuItem text="Verbinding maken" onAction="#handleVerbindingAction"/>
<SeparatorMenuItem />
<MenuItem text="Afsluiten" onAction="#handleCloseAction"/>
</items>
</Menu>
<Menu text="TAB">
<items>
<MenuItem text="Script toevoegen" onAction="#handleAboutAction"/>
<SeparatorMenuItem />
<MenuItem text="Script draaien" />
</items>
</Menu>
<Menu text="About" onAction="#handleAboutAction">
<items>
<MenuItem text="Op basis van wizard" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center> <Label text="Add New Dock of Home" />
</center>
我已经看到可以从应用程序的 start 方法执行此操作。但是由于结构的原因,我想在 Main.java 中实现它,并且我主要使用 FXML 来声明 GUI。