My question seems to be very much related to How to hide JDialog from JApplet when user switch browser tab? But it does not provide a working solution.
I have developed an applet deployed using JWS/JNLP. It starts with showing "NEW GAME" dialog.
private class NewGameDialog extends CustomDialog implements ActionListener {
...
public NewGameDialog () {
super(topContainer, "NEW GAME", modalityType);
System.out.println(topContainer + " " + modalityType);
//prints JApplet and DOCUMENT_MODAL
...
CustomDialog
just extends JDialog
:
public class CustomDialog extends JDialog implements WindowListener {
public CustomDialog(Container cont, String title, ModalityType modalityType) {
super(windowForComponent(cont), title, modalityType);
}
public static Window windowForComponent(Component c) {
if (c instanceof Window) return (Window) c;
return SwingUtilities.windowForComponent(c);
}
...
This is how JDialog
is invoked from a GUI class:
public void requestNewGame () {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
NewGameDialog dialog = new NewGameDialog();
dialog.setVisible(true);
}
});
}
I have used different types of modality described in How to Use Modality in Dialogs. The goal is to hide JDialog
when user switches to another tab in browser. But none of options does not seems to work. The dialog keeps floating above all tabs.
Please, advice how can I hide the dialog when user moves to another tab and show again once user returns to my applet's tab?