tennisclub tennisclub - 1 year ago 78
Java Question

How does control flow in JavaFX Application?

My experience with JavaFX is small.I searched internet but still I cannot get one thing: when application.launch(args) is called will this function run till application is closed or not.

I ask this because I used QT before and there function that launches window returns immediately and execution of code below this function call continues while window is displayed. However in case of JavaFX application control stays in this launch function and code below it refuses to execute while application is open. Is it supposed to be so or it is related to problems in my application code(extended from Application)?

Answer Source

You cannot call application.launch more than once, it returns no value until the application has terminated:

Launch a standalone application. This method is typically called from the main method(). It must not be called more than once or an exception will be thrown. The launch method does not return until the application has exited, either via a call to Platform.exit or all of the application windows have been closed.

Typical usage is:

public static void main(String[] args) { Application.launch(MyApp.class, args); } where MyApp is a subclass of Application.

See the documentation here

I too was confused about this in the beginning however yes if your application has code below application.launch it wont be performed essentially until you close the application window etc.

If you are looking for a work around to have the window open theres some solutions offered here

Anyway hope this answers your question and good luck with your project :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download