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

incorrect focus events when activating window

XMLWordPrintable

    • x86
    • linux

      run the test, window will be unfocused, click on the button in this window to focus it
      you will see that focus will go to the frame first and then bounced to window,
      It should go to the window directly,

      import java.awt.AWTEvent;
      import java.awt.Button;
      import java.awt.Frame;
      import java.awt.Toolkit;
      import java.awt.Window;
      import java.awt.event.AWTEventListener;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;

      /**
       *
       * @author son
       */
      public class FocusInWindow {
          public static void main(String[] args) {
              Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
                  public void eventDispatched(AWTEvent event) {
                      System.out.println("AWTEventListener(): " + event);
                  }
              }, AWTEvent.FOCUS_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK | AWTEvent.WINDOW_FOCUS_EVENT_MASK);
              WindowDisposer disposer = new WindowDisposer();
              Frame frame = new Frame("Frame") { public String toString() { return "frame"; } };
              Button fbtn = new Button("frame button") { public String toString() { return "frame button"; } };
              frame.add(fbtn);
              frame.pack();
              frame.addWindowListener(disposer);
              frame.setVisible(true);

              Window window = new Window(frame) { public String toString() { return "window"; } };
              Button wbtn = new Button("frame button") { public String toString() { return "window button"; } };
              window.add(wbtn);
              window.pack();
              window.setLocation(300, 300);
              window.setVisible(true);

              Frame frame1 = new Frame("Frame1") { public String toString() { return "frame1"; } };
              Button fbtn1 = new Button("frame button") { public String toString() { return "frame1 button"; } };
              frame1.add(fbtn1);
              frame1.pack();
              frame1.addWindowListener(disposer);
              frame1.setLocation(0, 300);
              frame1.setVisible(true);
          }
      }

      class WindowDisposer extends WindowAdapter {
          public void windowClosing(WindowEvent e) {
              e.getWindow().dispose();
          }
      }

            arapte Ambarish Rapte
            son Oleg Sukhodolsky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: