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

Motif: Focus not returned after window is re-activated



    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.1.1, 1.1.7
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      solaris_2.5.1, windows_95


      Name: mc57594 Date: 06/17/97

              When a window is reactivated, focus is not returned
              to the widget that was last in focus.

      Sample program:
              The program creates a frame window that contains a button.
              The button is a key listener that outputs any key events it
              receives from the console.

              1) De-activate the window by switching to another application.
              2) Re-activate the sample program.

      import java.awt.*;
      import java.awt.event.*;

      public class w extends Frame implements WindowListener
              MyButton b;

              public W()
                      b = new MyButton("button");
                      b.setBounds(40, 70, 80, 40);

              public static void main(String args[])
                      Frame f = new w();
                      f.setSize(200, 200);

      public void windowOpened(WindowEvent e) {}
      public void windowClosing(WindowEvent e)
      public void windowClosed(WindowEvent e) {}
      public void windowIconified(WindowEvent e) {}
      public void windowDeiconified(WindowEvent e) {}
      public void windowActivated(WindowEvent e) {}
      public void windowDeactivated(WindowEvent e) {}

      class MyButton extends Button implements KeyListener
              MyButton(String s)

              public void keyTyped(KeyEvent e) {

              public void keyPressed(KeyEvent e)

              public void keyReleased(KeyEvent e) {}


      [chamness 6/17/97] Another user says:

      Name: David P. White
      Company: HMS Software
      Synopsis: Focus Not Handled Properly After Window De-Activated And Re-Activated


      Compile and run the code which follows. It will present a Frame with
      three TextFields. When the Frame is first shown, AWT sets focus to the
      first TextField (there appears to be no way to override this behavior) so
      that any keystrokes are identified as being sent to the component named tf1.
      When the Frame looses focus to another window (is de-activated) and the
      focus is returned to the Frame (by clicking the mouse on the Frame's title
      bar) the bug can be seen. The focus is NOT returned to the component which
      had the focus at the time the Frame was de-activated. Instead the focus is
      given to the Frame itself.

      You can watch the program's trace output in the console window. After the
      Frame is first shown, the focus is set to component named tf1 and any
      keystrokes typed are directed to that component. De-Activate and re-activate
      the Frame, then enter keystrokes. You will see that they are delivered to
      the Frame.

      Perhaps this is somehow by design but this is brain-dead and inconsistent
      behavior. It essentially forces the subclassing of the frame and its
      implementation of the WindowListener interface so that simple focus control
      can be provided.


      import java.awt.*;
      import java.awt.event.*;

      public class jdk111FocusLostBug extends Frame
                                      implements WindowListener,
         private TextField tf1 = null;
         private TextField tf2 = null;
         private TextField tf3 = null;

         public jdk111FocusLostBug()
            super("Focus Lost/Returned Bug");
            setLayout(new FlowLayout());
            tf1 = new TextField();
            tf2 = new TextField();
            tf3 = new TextField();

         public void keyTyped(KeyEvent e) {}

         public void keyPressed(KeyEvent e)
            System.out.println("Key Pressed In: " + ((Component) e.getSource()).getName());

         public void keyReleased(KeyEvent e) {}

         public void windowOpened(WindowEvent e) {}

         public void windowClosing(WindowEvent e) {}

         public void windowClosed(WindowEvent e) {}

         public void windowIconified(WindowEvent e) {}

         public void windowDeiconified(WindowEvent e) {}

         public void windowActivated(WindowEvent e)
            System.out.println("Window Activated");

         public void windowDeactivated(WindowEvent e)
            System.out.println("Window De-Activated");
         } aa

         public Dimension getPreferredSize()
            return(new Dimension(200, 75));

         public static void main(String[] argv)
            new jdk111FocusLostBug();


          Issue Links



              mmartaksunw Michael Martak (Inactive)
              mchamnessunw Mark Chamness (Inactive)
              0 Vote for this issue
              0 Start watching this issue