DDS
DDS

Reputation: 2478

How to prevent JFX Dialog to hide the application

I have a JFX program that should always be maximized covering the desktop, what happens to me is that when I start a dialog, like

 Alert dlg2 = new Alert(Alert.AlertType.ERROR);
 dlg2.setHeaderText("my Dialog");
 dlg2.setContentText("Error: unabvle to load");
 System.err.println("Unable to load ");
 dlg2.showAndWait();

The application window hides showing just the alert over the desktop. I need to keep the application showing hiding windows's desktop

Upvotes: 0

Views: 209

Answers (1)

Layynezz
Layynezz

Reputation: 112

The initOwner method might help.

The official oracle documentation says:

Specifies the owner Window for this dialog, or null for a top-level, unowned dialog. This must be done prior to making the dialog visible.

So setting the proprietary window causes the dialog to display above it. Try adding this method dlg2.initOwner(YourStage) to your alert. Remember that you must enter a parameter of type Stage.

Alert dlg2 = new Alert(Alert.AlertType.ERROR);
dlg2.setHeaderText("my Dialog");
dlg2.setContentText("Error: unabvle to load");
System.err.println("Unable to load ");
dlg2.initOwner(<YourStage>);
dlg2.showAndWait();

Upvotes: 2

Related Questions