问题
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?
回答1:
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();
来源:https://stackoverflow.com/questions/27866432/controls-fx-progress-dialog-modality-alert-modality