<Swing Dev> [macos] regression in dialog modality in High Sierra and Mojave

Vladislav Protasov vladislav.protasov at gmail.com
Thu Jan 31 10:55:08 UTC 2019


Hi Dmitry,

It was Java 8

Thanks,
Vlad

On Thu, Jan 31, 2019 at 5:25 PM Dmitry Markov <dmitry.markov at oracle.com>
wrote:

> Hi Vlad,
>
> I cannot reproduce the issue on High Sierra with JDK11 and JDK12. What
> version of java do you use?
>
> Thanks,
> Dmitry
>
> On 19 Nov 2018, at 10:52, Vladislav Protasov <vladislav.protasov at gmail.com>
> wrote:
>
> Hi All,
>
> Please see
> https://bugs.openjdk.java.net/browse/JDK-8182638
> it was marked as fixed but now the test fails again
> in High Sierra and Mojave:
>
> Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: The
> second dialog window was not on top
> at
> com.infolytik.ui.JDialog392$SecondDialogListener.windowOpened(JDialog392.java:160)
>
>
> Also, there is another (maybe related) problem which is only
> reproducible in  High Sierra and Mojave (but works ok in plain  Sierra)
>
> Steps:
> 1. run sample DialogModalityTest2,
>
> 2. See a frame with the button "Show Dialog 1"
>
> 3. Press Command+Tab to switch to another application, then Command+Tab
> again to come back.
>
> 4. Click "Show Dialog 1", then click  "Show Dialog 2", close Dialog 2.
>
> 5. Notice that Dialog 1 is not closed while setVisible(false) and
> dispose() were called on both dialogs. Dialog 1 becomes non-modal zombie
> dialog.
>
>
> repeat steps 1,2, 4 (without step 3) and notice that Dialog 1 was closed
> as expected.
>
> public class DialogModalityTest2 extends JFrame {
>     private JDialog dlg1, dlg2;
>
>     public DialogModalityTest2() {
>         super("Frame");
>         setDefaultCloseOperation(EXIT_ON_CLOSE);
>         setBounds(100, 100, 300, 300);
>         dlg1 = new Dialog1(this);
>         dlg2 = new JDialog(dlg1, "Dialog 2", true);
>
>
>         dlg2.addWindowFocusListener(new WindowFocusListener() {
>             @Override
>             public void windowGainedFocus(WindowEvent e) {
>                 System.out.println("dlg2 windowGainedFocus " + e);
>             }
>
>             @Override
>             public void windowLostFocus(WindowEvent e) {
>                 System.out.println("dlg2 windowLostFocus " + e);
>             }
>         });
>
>         dlg1.addWindowFocusListener(new WindowFocusListener() {
>             @Override
>             public void windowGainedFocus(WindowEvent e) {
>                 System.out.println("! dlg1 windowGainedFocus " + e + " " + dlg1);
>
>             }
>
>             @Override
>             public void windowLostFocus(WindowEvent e) {
>                 System.out.println("! dlg1 windowLostFocus " + e + " " + dlg1);
>                 printFocus();
>
>                 System.out.println();
>                 System.out.println("windowLostFocus printFocus again in invokeLater...");
>                 SwingUtilities.invokeLater(() -> printFocus());
>             }
>         });
>
>         JButton button = new JButton("Show Dialog 1");
>
>         button.addActionListener(e -> {
>             dlg1.setBounds(300, 150, 300, 200);
>             dlg1.setVisible(true);
>
>             System.out.println();
>             System.out.println("button.addActionListener DIALOG 1 closed");
>             printFocus();
>
>             System.out.println();
>             System.out.println("button.addActionListener printFocus again in invokeLater...");
>             SwingUtilities.invokeLater(() -> printFocus());
>
>         });
>
>         setLayout(new FlowLayout());
>         add(button);
>         JButton dummy = new JButton("Dummy");
>         add(dummy);
>
>         dummy.addActionListener(e -> {
>             printFocus();
>         });
>
>     }
>
>     private void printFocus() {
>         System.out.println("getFocusedWindow =" + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow());
>         System.out.println("frame is isFocused=" + DialogModalityTest2.this.isFocused());
>         System.out.println("getFocusOwner =" + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
>     }
>
>     private class Dialog1 extends JDialog {
>         private Dialog1(JFrame owner) {
>             super(owner, "Dialog 1", true);
>             JButton button = new JButton("Show Dialog 2");
>
>             button.addActionListener(e -> {
>                 Window[] ownerlessWindows = getOwnerlessWindows();
>                 System.out.println("ownerlessWindows:" + ownerlessWindows.length);
>
>                 dlg2.setBounds(500, 225, 250, 100);
>                 dlg2.setVisible(true);
>
>
>                 dlg1.setVisible(false);
>                 dlg1.dispose();
>
>                 System.out.println("1 isVisible? " + dlg1.isVisible() + " isShowing " + dlg1.isShowing() + " isModal " + dlg1.isModal() + " isActive " + dlg1.isActive());
>                 System.out.println("2 isVisible? " + dlg2.isVisible() + " isShowing " + dlg2.isShowing() + " isModal " + dlg2.isModal() + " isActive " + dlg2.isActive());
>
>
>                 System.out.println(dlg2);
>
>                 System.out.println("getFocusedWindow =" + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow());
>                 System.out.println("frame is isFocused=" + DialogModalityTest2.this.isFocused());
>
>                 ownerlessWindows = getOwnerlessWindows();
>                 System.out.println("ownerlessWindows:" + ownerlessWindows.length);
>
>                 for (Window w : ownerlessWindows)
>                     if (w instanceof JDialog)
>                         System.out.println("ownerlessWindow: " + w);
>
>                 Window[] window = getWindows();
>                 System.out.println(window.length);
>                 for (Window w : window)
>                     if (w instanceof JDialog)
>                         System.out.println(w);
>
>             });
>
>             add(button);
>         }
>     }
>
>     public static void main(String[] args) {
>         System.out.println(System.getProperty("java.version"));
>
>         EventQueue.invokeLater(() -> new DialogModalityTest2().setVisible(true));
>     }
> }
>
> Thank you,
> Vlad
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/swing-dev/attachments/20190131/a7c7b6a7/attachment-0001.html>


More information about the swing-dev mailing list