I'm trying to display a modal dialog in front of an Applet
.
My current solution fetches the root frame like so:
Frame getMyParent() {
Container parent = getParent();
while (!(parent instanceof Frame)) {
parent = ((Component)parent).getParent();
}
return (Frame)parent;
}
And creates the dialog as follows:
public OptionsDialog(MainApplet applet, boolean modal) {
super(applet.getMyParent(), "options", modal);
// ....
However often this shows the modal dialog below the frame, though the modal behaviour works correctly.
How can this be fixed?
Ideally this should be for Java versions 1.5 and above.
Modal dialog box — A dialog box that blocks input to some other top-level windows in the application, except for windows created with the dialog box as their owner. The modal dialog box captures the window focus until it is closed, usually in response to a button press.
There are two basic types of dialogs: modal and modeless. Modal dialogs block input to other top-level windows. Modeless dialogs allow input to other windows. An open file dialog is a good example of a modal dialog.
How to Create a Dialog Box in Java. There are several ways in which a developer can create a dialog box in Java. Programmers can use JDialog, JOptionPane, or ProgressMonitor. To create a standard dialog, you can simply use the JOptionPane class.
Modal dialog boxes, which require the user to respond before continuing the program. Modeless dialog boxes, which stay on the screen and are available for use at any time but permit other user activities.
JDialog dialog = new JDialog(SwingUtilities.windowForComponent(this));
dialog.setModal(true);
dialog.setSize(200, 200);
dialog.setVisible(true);
Frame f =(Frame)SwingUtilities.getAncestorOfClass(Frame.class,parentWindow); new JDialog(f,true);
(source = http://kb.trisugar.com/node/7613) works for parentWindow = sun.plugin2.main.client.PluginEmbeddedFrame
Use null insterad of applet.getMyParent()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With