I am writing an application with 2 different BorderPanes, BorderPane A and BorderPane B. The application has 2 menuitems, such that, when clicked it HAS to show BorderPane A or BorderPane B.
这是应用程序类, 它有我要使用的阶段
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();
}
}
在选择菜单时, 主雅瓦级有两个边框, 我想在应用程序上显示边板 。
Does someone knows how to show the Borderpane(set the Scene on Stage) from this method(showBorderPane)? I d like to retrieve the Stage and set the scene with de borderpane:
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);
}
时 时
我的主体. 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>
I ve seen it is possible to do this from the start method of the application. But I d like to implement it in the Main.java because of structure and I am using mainly FXML to declare the GUI.