1

I am developing a plugin for Eclipse. I am using JavaFX for multiple features of this plugin. I have a menu built into the UI of Eclipse with handlers for each command i.e. each feature clicked. For example: user clicks "Start Symbol Table" then the SymbolTableHandler is called.

Each of these handlers starts a JavaFX application from an Eclipse job to make sure the UI does not become unresponsive. The JavaFX applications use application.launch() to begin.

My problem is that when a user starts two features, an error is thrown due to the limitation of only being allowed to call application.launch() once.

This would not be a problem if all features started together as I could create new stages etc.

So is there a way to mimic application.launch multiple times so multiple tables/features of this plugin can be run together ?

I have come up with a solution if anyone cares for the code.

1 Answers1

1

Update October 2020

While some of the info in this answer is still relevant, some is outdated. For a more up to date answer to the similar question, see:


From the JavaFX Application javadoc, launch will do this:

  1. Constructs an instance of the specified Application class
  2. Calls the init() method
  3. Calls the start(javafx.stage.Stage) method
  4. Waits for the application to finish, which happens when either of the following occur: the application calls Platform.exit() the last window has been closed and the implicitExit attribute on Platform is true
  5. Calls the stop() method

So, instead of doing calling launch(), do the above tasks yourself (e.g. create your own custom launcher).

The launcher will also start the JavaFX platform, so you will need to trigger that indirectly, if it has not already been done, by creating a JFXPanel().

Of course, the tricky part is 4. Basically, you can't really do that and, because you can't do 4, you don't know when to do 5. So your "applications" will need to be written with some constraints (e.g. they don't call Platform.exit() as that would immediately shut down all of your active plugins). You could place a listener on the stage you create in your custom launcher and pass to step 3, so then when that stage is closed, the stop() method is called.

The solution outlined above is a little bit hacky, but may be workable for you.

See related:

jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • Thanks you, is there any standard when it comes to my kind of approach? Surely there are plugins out there that must create multiple FXML GUI's from a menu? – UnholySalmon Feb 26 '16 at 01:51
  • Your approach is not standard, most applications can just use the standard JavaFX launching facilities, but then again most applications are not Eclipse plugins. I encourage you to ask your questions regarding use of JavaFX in Eclipse plugins directly to the [e(fx)clipse community](http://www.eclipse.org/efxclipse/community.html), who would be the experts in this field. – jewelsea Feb 26 '16 at 07:47
  • i have come up with a solution for anyone that wants to use JavaFX for an eclipse plugin with multiple UI's created from different handlers. – UnholySalmon Mar 21 '16 at 02:50
  • As of 2020 and JavaFX 14.0.1, I found this answer allowed me to make two JavaFX windows: https://stackoverflow.com/a/59542435/3006011. I did not use Platform.exit(); as the last line in main() because that caused an error for me. – saner Oct 07 '20 at 00:04
  • 1
    @eriksan thanks for info on `Platform.startup()`, I updated the answer to reference the more up to date info. – jewelsea Oct 07 '20 at 15:15