Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4284547
Votes 6
Synopsis textField.requestFocus on window activation can leave 2 fields flashing
Category java:classes_swing
Reported Against 1.2.2
Release Fixed
State 11-Closed, duplicate of 4290675, bug
Priority: 3-Medium
Related Bugs 4290675 , 4333326
Submit Date 25-OCT-1999
Description




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) 
======================================================================
Work Around




An easy workaround (in the context of this test case) is to
create the dialog new each time.
======================================================================
Evaluation




This is not reproducible with Merlin focus API.

  xxxxx@xxxxx   2000-10-11

======================================================================
Comments
  
  Include a link with my name & email   

Submitted On 14-APR-2000
joshid
One way I've been able to get around it is in the 
windowActivated() method to put the following line of code:

field2.getCaret().setVisible(false);


Submitted On 13-JUN-2000
raoky1
hi Joshid,
I did get your work around.
field2.getCaret().setVisible(false);
where is the method getCaret()
Koteswara rao Yaramothu
kyaramothu@fujifilmsoft.com






PLEASE NOTE: JDK6 is formerly known as Project Mustang