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

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u92, 9
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b137
    • OS:
      os_x

      Backports

        Description

        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();
                }
            }
        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  ant Anton Tarasov
                  Reporter:
                  ant Anton Tarasov
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: