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

Listening to focusedWindow property changes

    XMLWordPrintable

Details

    • x86
    • windows_nt

    Description

      Name: pzR10082 Date: 10/23/2000



      My application creates 2 windows and adds a PropertyChangeListener
      to KeyboardFocusManager to track focus transfers between them. When
      i switch between windows, this listener is called two times. When it
      is called for the first time, the new focusedWindow is reported to be
      null. This should mean that the focused Window is not in the calling
      application's context, which is not the case.

      So currently an application has no way to distinguish between focus
      transfers to another window created by this application and to a
      foreign window.

      Here's a test case:

      ---------------------------------------------
      import java.awt.*;
      import java.awt.event.*;
      import java.beans.*;

      public class WindowSwitch implements PropertyChangeListener
      {
          public static void main(String[] argv) {
              Frame f1 = new Frame("1");
              f1.setBounds(100,100,100,100);
              Frame f2 = new Frame("2");
              f2.setBounds(210,100,100,100);

              KeyboardFocusManager.getCurrentKeyboardFocusManager().
                  addPropertyChangeListener("focusedWindow", new WindowSwitch());
              f1.setVisible(true);
              f2.setVisible(true);
          }

          public void propertyChange(PropertyChangeEvent ev) {
              Window w1 = KeyboardFocusManager.getCurrentKeyboardFocusManager().
                  getFocusedWindow();
              Window w2 = (Window)ev.getNewValue();
              System.out.println("w1 = " + w1 + ", w2 = " + w2);
          }
      }
      ---------------------------------------------

      ======================================================================

      Attachments

        Activity

          People

            bagiras Oleg Pekhovskiy (Inactive)
            peterz Peter Zhelezniakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: