2017-05-07 84 views
0

我正在嘗試使用方法調用另一個fxml頁面,但獲取下面的錯誤。嘗試在javaFX中使用方法調用來啓動新的FXML文件

java.lang.IllegalStateException:不在FX應用程序線程上; currentThread = AWT-EventQueue的-0在在 com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)在 com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236) com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423) at javafx.stage.Stage。(Stage.java:241)at javafx.stage.Stage。(Stage.java:227)在 thebio.MainController.StudentRegistration(MainController.java:134)

下面的方法,我在開展這項活動中使用的,我不知道我在哪裏得到它錯了,請,任何援助一定會很感激。

public void StudentRegistration(){ 
    try { 
     Platform.setImplicitExit(false); 
     Parent root1; 
     root1 = FXMLLoader.load(getClass().getResource("Student.fxml")); 
     Stage stage = new Stage(); 
     stage.setTitle("ABC"); 
     stage.setScene(new Scene(root1)); 
     stage.show(); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
} 

謝謝。

回答

2

使用Platform#runLater更新GUI非GUI線程

Platform.runLater(()->{ 
    Parent root1; 
    root1 = FXMLLoader.load(getClass().getResource("Student.fxml")); 
    Stage stage = new Stage(); 
    stage.setTitle("ABC"); 
    stage.setScene(new Scene(root1)); 
    stage.show(); 
}); 
+0

感謝的是,我做appreciate.i是新來的JavaFX,我不知道我是多麼要實現該請。 我真誠地感謝你的快速反應。 –

+0

它的工作,謝謝。 –

+0

如果我想關閉以前的fxml,該怎麼辦? –

相關問題