我有# closeMethod ,当用户转到我的应用中的文件 - >退出时会被调用:
public void closeProgram(){
int choice = JOptionPane.showConfirmDialog(null, "Do You want to exit the program ? ", "Exit Panel", JOptionPane.YES_NO_OPTION);
if(choice == JOptionPane.YES_OPTION){
Thread ending = new Thread(){
@Override
public void run(){
aboutDevelopers();
}
};
ending.start();
System.exit(0);
}
}
我在这里有# aboutDevelopers 方法: 当通过File-> AboutDevelopers调用它时,它会很好地显示但是在closeProgram()上,它会崩溃。
public void aboutDevelopers(){
try {
Stage stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("AboutUsLayout.fxml"));
Scene scene = new Scene(root);
stage.setTitle("About Developers");
stage.setScene(scene);
stage.setResizable(false);
stage.show();
} catch (IOException ex) {
Logger.getLogger(FirstLayoutController.class.getName()).log(Level.SEVERE, null, ex);
}
}
我希望程序等待用户关闭 AboutUsLayout 窗口,然后退出。
我的堆栈跟踪:
Executing D:\Tilak\BeansProjects\WhatsThePassword\dist\run1156653616\WhatsThePassword.jar using platform C:\Program Files\Java\jdk1.8.0_05\jre/bin/java
Exception in thread "Thread-6" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-6
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:210)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:393)
at javafx.stage.Stage.<init>(Stage.java:233)
at javafx.stage.Stage.<init>(Stage.java:219)
at password.FirstLayoutController.aboutDevelopers(FirstLayoutController.java:470)
at password.FirstLayoutController$1.run(FirstLayoutController.java:412)