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

Motif: Focus not returned after window is re-activated

    XMLWordPrintable

    Details

    • 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

      Description



      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.

      Steps:
              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()
              {
                      setLayout(null);
                      b = new MyButton("button");
                      add(b);
                      b.setBounds(40, 70, 80, 40);
                      b.requestFocus();
                      b.setBackground(Color.red);
                      addWindowListener(this);
              }

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


      public void windowOpened(WindowEvent e) {}
      public void windowClosing(WindowEvent e)
      {
      System.exit(0);
      }
      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)
              {
                      super(s);
                      addKeyListener(this);
              }

              public void keyTyped(KeyEvent e) {
                              System.out.println(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

      Description:
      /*

      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,
                                                 KeyListener
      {
         private TextField tf1 = null;
         private TextField tf2 = null;
         private TextField tf3 = null;

         public jdk111FocusLostBug()
         {
            super("Focus Lost/Returned Bug");
            addWindowListener(this);
            addKeyListener(this);
            setName("Frame");
            setLayout(new FlowLayout());
            tf1 = new TextField();
            tf1.setName("tf1");
            tf1.addKeyListener(this);
            tf2 = new TextField();
            tf2.setName("tf2");
            tf2.addKeyListener(this);
            tf3 = new TextField();
            tf3.setName("tf3");
            tf3.addKeyListener(this);
            add(tf1);
            add(tf2);
            add(tf3);
            invalidate();
            validate();
            pack();
            show();
         }

         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();
         }
      }



        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mmartaksunw Michael Martak (Inactive)
              Reporter:
              mchamnessunw Mark Chamness (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: