• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using hide() in javafx doesn't work (eclipse)

 
Niko Belg
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have created a class called App that extends Application (JavaFX). In it, I have 2 stages that are displaying a few buttons. This App class is instantiated in main then passed as an argument to another class/thread called Controller (a has-a relationship). Once Controller receives an event, it calls app.hideGUI(); the contents of the function are:



Also, in the App class I have the following:



However, this does not work. It either crashes or simply does not hide the stages. Please advice me on why and how to fix this.

Thank you
 
John Damien Smith
Ranch Hand
Posts: 299
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Once Controller receives an event, it calls app.hideGUI();

I have no idea how your controller receives an event. I am guessing the event is being sent to the controller on a thread which is not the JavaFX application thread.
If this is the case you need to surround your code in a Platform.runLater construct to allow that code to execute on the JavaFX application thread.


I don't know if the above is your issue or your only issue.

Note that if you hide all the stages, the JavaFX runtime will exit, so if you want to temporarily hide the stages and then at a later time show them again, then you need to keep the platform running by invoking Platform.setImplicitExit(false); before you hide the stages. If you do that you will eventually need to explicitly exit the JavaFX platform at some stage when your application is supposed to shut down. You can do this by calling Platform.exit();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic