10

I need to creat an app that shows the primary stage to the user, and if the user closes the stage, instead of finishing the application, it should just hide the stage for later use. On swing we could just call setVisible(false) to a JFrame or JDialog, but how to do it on JavaFX?

5
  • There's no real concept of "disposing" a stage in JavaFX. If a stage is hidden and the reference goes out of scope, its resources will be cleaned up. If you keep a reference in scope, then you can call show() on it at a later time to display it again. Commented Sep 2, 2015 at 14:05
  • The problem is, i have a daemon thread that runs on background and takes some time to finish. And when it finish, it should open the stage again. The problem is that when the user closes the window, the application stops. Commented Sep 2, 2015 at 14:17
  • 2
    You coul'd minimize you application to the system tray. Here is an example javafx-demos.googlecode.com/svn-history/r100/trunk/javafx-demos/… Commented Sep 2, 2015 at 14:24
  • 1
    If your thread operates that way then it shouldn't be daemon (Pretty much the definition of a non-daemon thread is that it should keep the system from exiting until it's done). Commented Oct 13, 2016 at 21:56
  • You're right, i was trying to solve a problem the wrong way back when i asked the question. Commented Oct 14, 2016 at 13:54

1 Answer 1

31

Once the JavaFX toolkit has started, by default it will close down when the last visible window is closed.

To prevent this, you can call

Platform.setImplicitExit(false); 

You typically do this in your start(...) method, though it can be called from any thread.

To exit the application, you would then need to call

Platform.exit(); 

(as the application no longer exits automatically).

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry if this is a bit dated, but out curiosity, would you happen to know how to show a program that has been hidden?
Assuming you mean show a window that has been hidden, I would imagine that calling show() would do what you want.
Can we implement system tray alongside those actions?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.