JDK-8091080 : [Application] FX cannot be only initialized
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: application-lifecycle
  • Affected Version: 7u45
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2013-12-19
  • Updated: 2017-05-18
  • Resolved: 2017-05-18
Related Reports
Duplicate :  
Description
Application lifecycle and JavaFX are tied. There is no easy way to only initiate FX.

In an OSGi environment this can be a problem because each bundle has its own lifecycle. So, there is no direct way for a bundle to know whether FX is initialized or not.

The most simple thing would be to separate FX initialization (which could be performed by an early executed bundle - or maybe Java command line arg) and other bundles which could freely create stages (without having to deal with FX initialization).

Could be good to initialize FX via something like Platform.init(args) or/and to have a command line argument to ask so such as -Dfxinit
Comments
Duplicate of JDK-8090585 which is implemented in JDK 9.
18-05-2017

Yes, or even "Stage Platform.getMainStage()" which would have given the Stage as you mentioned (entire screen...).
07-01-2014

Got it. The advantage of having the stage created for you is that on embedded platforms, the stage can take up the entire screen and can have the correct trim and you don't need to guess at a size for it. Personally, I would have had people write "new Stage()" but that boat has sailed a while back.
06-01-2014

I'm in an OSGi environment where there is no "main" concept. The application is the sum of several bundles which may display things or not. So I need to ensure JavaFX is initialized before starting graphic related bundles. At present time I made a simple JavaFX bundle with the code extract given before and I give it a high priority in order to let it start first. The purpose of this request is to have a clean way to initialize JavaFX, or, even better, to have a Java command line option to do so (so I could get rid of this initilization bundle). Anyway it is bizarre not to have all windows/stages created the same way: on one hand you have the first (default/main) Stage, and then, on the other hand you can create others. Not to mention that if you want a special Stage (subclass, styled...) you have to throw away the first one and create yours. Where is the advantage? Not to write down "new Stage()"? PS: It's not a Thread issue ;)
06-01-2014

Like many GUI toolkits, FX is apartment threaded. Further, there is a single distinguished UI thread where windows are created and disposed and events from the underlying operating system are delivered. If you attempt to have multiple UI threads, this will fail. Given this, I'm wondering why it is necessary to initialize FX independent of creating a GUI for it to run.
06-01-2014

What you have seems like a fine solution for now; I would note that stage.hide() is unnecessary since the stage is not shown unless the application explicitly calls stage.show(). We can consider whether additional API might make sense in the future.
06-01-2014

"I am wondering why this matters but you will tell me in this bug report." => Already explained in the description but it seems not to be clear enough :S Well, I would like JavaFX to be inialized without having to create any graphical object. At the present time I have to do a workaround for this (FXInit.initialize()), which implementation is basically the following one: public final class FXInit extends Application { private static BlockingQueue<FXInit> sync= new SynchronousQueue<>(); public static FXInit initialize(final String... args) throws InterruptedException { new Thread(() -> FXInit.launch(FXInit.class, args)).start(); try { return sync.take(); } finally { sync= null; } } public void start(final Stage stage) throws InterruptedException { stage.hide(); sync.put(this); } }
06-01-2014

I am wondering why this matters but you will tell me in this bug report. <g>
19-12-2013