當嘗試關閉當前場景並在選擇menuItem時打開另一個場景時出現問題。我的主舞臺被編碼如下:在javaFX中切換場景
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Shop Management");
Pane myPane = (Pane)FXMLLoader.load(getClass().getResource
("createProduct.fxml"));
Scene myScene = new Scene(myPane);
primaryStage.setScene(myScene);
primaryStage.show();
}
然後內createProduct.fxml,當菜單項是的onclick,它會執行這樣的:
public void gotoCreateCategory(ActionEvent event) throws IOException {
Stage stage = new Stage();
stage.setTitle("Shop Management");
Pane myPane = null;
myPane = FXMLLoader.load(getClass().getResource("createCategory.fxml"));
Scene scene = new Scene(myPane);
stage.setScene(scene);
stage.show();
}
它開闢了createCategory.fxml。但是,前面的createProduct.fxml面板沒有關閉。我知道有一些名爲stage.close()來做到這一點,但我不知道在哪裏實現它,因爲我從一開始就沒有從主要的右邊傳遞場景。我想知道我應該如何解決這個問題。
在此先感謝。
您確定您需要在新階段打開其他屏幕(createCategory.fxml)嗎? –
我想要像你知道的Jframe一樣做? getJFrame()。dispose(); \t \t \t \t \t \t \t eForumForgotPwd mywindow的新= eForumForgotPwd(); \t \t \t \t \t \t \t myWindow.getJFrame()。setVisible(true);我需要在打開新窗口前關閉當前窗口 –