JDK-4284547 : textField.requestFocus on window activation can leave 2 fields flashing
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-10-25
  • Updated: 2000-10-23
  • Resolved: 2000-10-23
Related Reports
Duplicate :  
Relates :  
Description

Name: skT88420			Date: 10/25/99


It appears that calling textField.requestFocus() on window
activation, for a window that previously existed, can leave more
than one text field with its text insertion cursor flashing.

In the following test case, when you execute it, press the
button.  That will bring up a dialog with two JTextField objects.
Click on the second one, then click on the "X" to dispose the
dialog.  Then press the button on the main frame again, which
will bring up the dialog again and put the focus on the first
field.

When I do this, I see the text insertion cursor flashing in BOTH
fields, not just the one with the focus.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TextCursorTest extends JFrame {
   FieldDialog  dialog   = null;

   public TextCursorTest() {
      JButton  button   = new JButton();
      button.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent evt) {
                  if (dialog == null)
                     dialog   = new FieldDialog();
                  dialog.show();
               }});
      getContentPane().add(button);
      pack();
      show();
   }
   
   public static void main(String[] args)
   { TextCursorTest test  = new TextCursorTest();}

   public static class FieldDialog extends JDialog {
      JTextField  field1;
      JTextField  field2;

      public FieldDialog() {
         setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
         addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent evt) { dispose(); }
               public void windowActivated(WindowEvent evt)
               { field1.requestFocus(); }
            });
         getContentPane().setLayout(new BorderLayout());
         field1   = new JTextField();
         field2   = new JTextField();
         getContentPane().add(field1, BorderLayout.NORTH);
         getContentPane().add(field2, BorderLayout.SOUTH);
         pack();
      }
   }
}
(Review ID: 96994) 
======================================================================

Comments
WORK AROUND Name: skT88420 Date: 10/25/99 An easy workaround (in the context of this test case) is to create the dialog new each time. ======================================================================
11-06-2004

EVALUATION Name: pzR10082 Date: 10/11/2000 This is not reproducible with Merlin focus API. ###@###.### 2000-10-11 ======================================================================
11-10-2000