Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8160570

[macosx] modal dialog can skip the activation/focus events

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8u92, 9
    • client-libs
    • b137
    • os_x

        This is timing dependent, but it can happen that a modal dialog doesn't receive WINDOW_ACTIVATION & WINDOW_GAINED_FOCUS events when first shown. The following test forces "the right timings" & reproduces the bug:

        public class Main {
            public static void main(String[] args) throws InterruptedException {
                EventQueue.invokeLater(() -> runGUI());
            }

            static void runGUI() {
                JFrame f = new JFrame("frame");
                JDialog d = new MyModalDialog(f, "dialog");
                d.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowActivated(WindowEvent e) {
                        System.out.println(e);
                    }
                });
                d.addWindowFocusListener(new WindowAdapter() {
                    @Override
                    public void windowGainedFocus(WindowEvent e) {
                        System.out.println(e);
                    }
                });
                f.setVisible(true);
                d.setVisible(true);
            }

            static class MyModalDialog extends JDialog {
                public MyModalDialog(Frame owner, String title) {
                    super(owner, title, true);
                }

                @Override
                public boolean getFocusableWindowState() {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ignore) {
                    }
                    return super.getFocusableWindowState();
                }
            }
        }

              ant Anton Tarasov (Inactive)
              ant Anton Tarasov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: