-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.2
-
x86
-
windows_nt
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)
======================================================================
- duplicates
-
JDK-4290675 Focus Management Enhancements
- Closed
- relates to
-
JDK-4333326 Multiple active carets - ambiguous focus
- Closed