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

Window.getMostRecentFocusOwner() returns null

    XMLWordPrintable

    Details

    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      If we are calling Window.getMostRecentFocusOwner() method in the windowGainedFocus() method of window focus listener, added to JFrame, Window.getMostRecentFocusOwner() returns null. I think, this is not OK.

      Then the test program is opened, and focus is moving out from the test program window, output is not null. But then focus is moved to the test program window from outside, for example, from another application to one of two text fields, the output value, that is the result of Window.getMostRecentFocusOwner(), is null.

      Here is the test program:
      -----------------------BEGIN SOURCE--------------------------------------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class awttest {
          public static void main(String[] args) {
              final JFrame frame = new JFrame("Test");
              frame.setLayout(new java.awt.FlowLayout());

              JTextField tf1 = new JTextField(10);
              JTextField tf2 = new JTextField(10);

              Container cp = frame.getContentPane();
              cp.add(tf1);
              cp.add(tf2);

      frame.addWindowFocusListener(new WindowAdapter() {
      public void windowGainedFocus(WindowEvent e) {
      System.out.println(frame.getMostRecentFocusOwner());
      }
      public void windowLostFocus(WindowEvent e) {
      System.out.println(frame.getMostRecentFocusOwner());
      }
      });

              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);
          }
      }

      -----------------------END SOURCE----------------------------------------
      ###@###.### 2004-12-21 19:48:14 GMT

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            draskinsunw Daniel Raskin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: