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

getOppositeWindow() method returning null from Window Focus events

    XMLWordPrintable

Details

    • beta2
    • generic
    • solaris_7
    • Verified

    Description

      While switching focus between java frames, WINDOW_GAINED_FOCUS, WINDOW_LOST_FOCUS, WINDOW_ACTIVATED, and WINDOW_DEACTIVATED events are generated as expected. However, getOppositeWindow() method is always returning null.

      - This is occuring on Solaris 2.7, Solaris IA 2.7, and Linux platforms. This bug does not occur on Win98.

      - The bug occurs with either AWT Frame or Swing JFrame.

      - Tested with build jdk1.4 Build 40

      Steps to reproduce:

      1) Compile and run attached sample code "AwtOppositeWindow.java"

      2) After GUI comes up, just click back and forth on each window and observe the window focus events generated.


      rick.reynaga@eng 2000-11-16
      ---------------------------
      Attaching AwtOppositeWindow.java sample to reporduce bug:

      import java.awt.*;
      import java.awt.event.*;
      import java.applet.*;
      import java.util.*;

      public class AwtOppositeWindow extends Frame implements FocusListener, ActionListener, WindowFocusListener {

      Frame frame1, frame2;
      Button button1, button2;
      TextArea textarea1, textarea2;
      Checkbox chkbox;
      java.awt.List list;

      Component focusGainedWindow=null;
      Component focusLostWindow=null;

      KeyboardFocusManager manager;

      public AwtOppositeWindow() {

      manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();

      frame1 = new Frame("TestFrame1");
      frame1.setLayout(new FlowLayout());
      frame1.setSize(200,200);
      frame1.setBackground(Color.orange);

      frame2 = new Frame("TestFrame2");
      frame2.setLayout(new FlowLayout());
      frame2.setSize(200,200);
      frame2.setBackground(Color.pink);

      button1 = new Button("Button 1");
      button1.addFocusListener(this);
      button1.addActionListener(this);

      button2 = new Button("Button 2");
      button2.addFocusListener(this);

      textarea1 = new TextArea("TextArea", 3,10);
      textarea1.addFocusListener(this);

      textarea2 = new TextArea("TextArea", 3,10);
      textarea2.addFocusListener(this);

      list = new java.awt.List(2);
      list.add("Item 1");
      list.add("Item 2");
      list.addFocusListener(this);

      chkbox = new Checkbox("Checkbox", false);
      chkbox.addFocusListener(this);

      frame1.add(button1);
      frame1.add(textarea1);
      frame1.add(list);

      frame2.add(button2);
      frame2.add(textarea2);
      frame2.add(chkbox);

      frame1.setLocation(0,50);
      frame1.setVisible(true);
      frame1.addWindowListener(this);

      frame2.setLocation(0,250);
      frame2.setVisible(true);
      frame2.addWindowListener(this);
              
      }

      public void actionPerformed(ActionEvent ae) { }

      public void windowGainedFocus(WindowEvent we) {
      System.out.println("\n** windowGainedFocus Method" );
                      focusLostWindow = we.getOppositeWindow();
                      if (focusLostWindow == null) {
                          System.out.println("** Warning: getOppositeWindow() is null");
                      }
                      System.out.println(we);
      }

      public void windowLostFocus(WindowEvent we) {
      System.out.println("\n** windowLostFocus Method" );
                      focusGainedWindow = we.getOppositeWindow();
                      if (focusGainedWindow == null) {
                          System.out.println("** Warning: getOppositeWindow() is null");
                      }
                      System.out.println(we);
              }

      public void windowActivated(WindowEvent we){
      System.out.println("\n** windowActivated Method" );
                      if (we.getOppositeWindow() == null) {
                          System.out.println("** Warning: getOppositeWindow() is null");
                      }
                      System.out.println(we);
      }

      public void windowDeactivated(WindowEvent we){
      System.out.println("\n** windowDeactivated Method" );
                      if (we.getOppositeWindow() == null) {
                          System.out.println("** Warning: getOppositeWindow() is null");
                      }
                      System.out.println(we);
      }
              
              public void windowOpened(WindowEvent we) { }
      public void windowClosing(WindowEvent we) { }
      public void windowClosed(WindowEvent we) { }
      public void windowIconified(WindowEvent we) { }
      public void windowDeiconified(WindowEvent we) { }

              public void focusLost(FocusEvent fe){ }
      public void focusGained(FocusEvent fe) { }

      public static void main(String args[]) {
      new AwtOppositeWindow();
          }
      }

      Attachments

        Activity

          People

            dmendenhsunw David Mendenhall (Inactive)
            rreynagasunw Rick Reynaga (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: