JavaFX : invoking ' Application.launch(args) ' from a method other than main [duplicate]

流过昼夜 提交于 2019-12-06 09:39:20

You need to call the static method of the class which extends Application. You can call it from anywhere, not mandatory to call it from main( ) . Use the following :

OpenSite.launch(OpenSite.class);

For background knowledge on how JavaFX Application works, please go through Application JavaDoc. It is very well written and throws a lot of insight on how JavaFX Application is triggered.

You can also go through the following answer

Starting JavaFX from Main method of class which doesn't extend Application

Notes

  • The thread which calls Application.launch() and launches the primary Stage will not return unless the Stage is closed.
  • Make sure you make the call to launch() just once.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!