So once again we are in the process of converting our existing Java application that was using entirely Swing to using JavaFX. However, the application will not be using JavaFX entirely. This seems to be causing some issues with Alerts/Dialogs and modality. We are currently using Java 8u40.
The main application is basically in a JFrame that has a Menu. The main content pane is JDesktopPane and clicking a MenuItem opens new JInternalFrames within the DeskopPane. Screens we are converting to JavaFX are basically JFXPanels within a JInternalFrame at the moment. Any Alerts/Dialogs that are opened from the JFXPanels are modal to the panel itself, but not to the JInternalFrame, DeskopPane, Menu, etc.
I read in the DialogPane documentation that they are planning to introduce some lightweight dialogs and even possibly InternalFrames in future releases of JavaFX, so maybe we'll just have to wait it out a little longer for this functionality. But, ideally when opening a new Alert/Dialog it would be modal to the entire Application.
EDIT: Currently doing the following for modal dialogs:
((Stage)getDialogPane().getScene().getWindow()).setAlwaysOnTop(true);
This makes the dialog always appear on top, however the dialog also remains on top of other applications even if our main application is minimized. It also does not block input to any Swing components in the frame.
I don't think i understand your question completely. But here is my guess - You are trying to make an alert window from some
JFXPanel
that will be modal (i.e. user will not be able to click in your application until she closes that alert window) to your entire application which is written partially using swing components.If your application would be written in purely JavaFX then you would do something like (Assuming you have created a button somewhere in your
JFXPanel
)but since
initOwner
requires ajavafx.stage.window
object passing a swing component won't work in your code. As of Java 8u40 i don't think there is a right way(i.e. not hacks) to set ownership ofAlert
objects to swing component. Not surprisingly such questions has already been asked here and not answered as of writing this.For your requirements you can use
JOptionPane.showMessageDialog
method and its look alike as workaround.These dialog boxes are modal by default so no work is necessary. You can call these from any event handler methods of JavaFX components.
I've done a little workaround with a small interface which is implemented in my JavaFXFrame:
And my JavaFXFrame implementation
}
And showing an Alert:
Hope this will help you