0

I have run into a little bit of an issue that I am not real sure on what to do.

My application will have a general application stage which will present the users with their options for work - i.e. a task list, or something like that.

When the users selects one of these options, I am to navigate to window to perform the work. They would like to have the general stage open always and open a another stage for the work to be done. I can do that with:

FXMLLoader loader = new FXMLLoader();
Parent node = loader.load(this.getClass().getResource("MyView.fxml").openStream());
Scene scene = new Scene(node);
Stage stage = new Stage();
stage.setTitle("You are working on - Blah Blah Blah....");
stage.setScene(scene);
stage.show();

This provides the desired look & feel - however it appears I am running into a threading issue when modal windows are presented.

For example - in one worker window I start a service and present a ControlsFX Progress Dialog as follows:

ProgressDialog progDiag = new ProgressDialog(service);
progDiag.setTitle("Busy");
progDiag.setHeaderText("Doing the work you asked me to do....");
service.start();

Let's assume that is a server call which is retrieving a lot of data - so while this is processing, I would like to move to the other open stage to work on it. However I can't, as the UI for the entire application is blocked by this control.

Secondly let's say an error occurs on one of the stages and we present the alert:

Alert error = new Alert(AlertType.ERROR);
error.setContentText("Something bad just happened....");
error.show();

This also blocks the entire UI rather than just the stage with the issue.

Is there a way in Java FX to open the stage in a new process/thread which won't be blocked by alerts on other stages?

purring pigeon
  • 4,141
  • 5
  • 35
  • 68

1 Answers1

2

I was able to solve my issue by providing a reference of the stage to the controller which will show the message. I am not crazy about this, as I will need to pass that reference around, but I didn't find another way to handle that..

ProgressDialog progDiag = new ProgressDialog(service);
progDiag.setTitle(title);
progDiag.initOwner(getPrimaryStage());
progDiag.setHeaderText(message);
progDiag.initModality(Modality.WINDOW_MODAL);
service.start();
purring pigeon
  • 4,141
  • 5
  • 35
  • 68
  • 2
    Doing it this way is right. You can define 3 different types of modality for a dialog (not modal, application modal, window modal). By using the first one the dialog / window is not modal and any window can be in front of it. By using an "application modal" mode the new dialog is always on top and no other window can be focused. The "window modal" type defines that the dialog is only for its parent window modal. By doing so you can not access the parent window but any other window. To do so the dialog needs a reference to it's parent window. – Hendrik Ebbers Jan 23 '15 at 07:47
  • Yes this is how I am able to handle it. Thanks. – purring pigeon Jan 25 '16 at 14:36