我必须通过单击树节点的JMenuItem来启动JavaFx应用程序,该节点扩展JApplet类并在Swing JFrame窗口上运行。
我在Swing应用程序中学习了JavaFx的教程 https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm和这个问题Run javafx and swing application at the same time并且我知道我必须在JavaFx应用程序线程上处理JavaFx数据。
所以我厌倦了点击JMenuItem通过Platorm.runlater线程启动JavaFx应用程序并确保JavaFx应用程序实现了Runnable接口,但我仍然遇到了这个错误:ToolKit not initialized。
以下是启动JavaFx Application
的JMenuItem的示例代码 static class OpenJavaFxApp extends JMenuItem{
OpenJavaFxApp(){
super("JavaFx App");
// This should launch JavaFx app
this.addActionListner(actionEvent -> Platform.runLater(() ->{
try{
// JavaFx app extends Application and
//impelents Runnable
JavaFxApp app = new JavaFxApp;
Stage anotherstage = new Stage();
app.start(anotherstage);
} catch(Exception e){
e.printstacktrace();
}
})
);
}
}
示例JavaFx应用程序代码
public class JavaFxApp extends Application implements Runnable{
@Override
public void start(Stage primaryStage){
AnchorPane pane = new AnchorPane();
pane.getChildren().addall(AddSomething);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(Strings[] args){
launch(args);
}
@Override
public void run(){
launch();
}
}
请对您的解决方案有所了解,但感谢任何帮助。感谢:)