-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.0_01
-
x86
-
windows_nt
Name: pa48320 Date: 01/10/2002
The following bug was originally entered as 4529881 and closed as a DUP of 4546077 which was closed as a DUP of 4587627. As of build 89 the original bug is still a problem. In fact, I don't see how they are related since the final bug seems to be bound up in JEditorPane while this is a fairly simple JTextField problem.
The following code shows the problem:
// TextFieldTest.java
// for testing behavior change on selecting contents of textfield
// on focusGained
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.*;
public class TextFieldTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setBounds(0,0,400,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = frame.getContentPane();
content.setLayout(null);
JTextField test1 = new JTextField();
test1.setBounds(10, 10, 80, 20);
test1.setText("test 1 field");
test1.addFocusListener(new TextFocusListener());
content.add(test1);
JTextField test2 = new JTextField();
test2.setBounds(10, 40, 80, 20);
test2.setText("test 2 field");
test2.addFocusListener(new TextFocusListener());
content.add(test2);
frame.setVisible(true);
}
}
// highlight contents when focus is gained
class TextFocusListener extends FocusAdapter {
public void focusGained(FocusEvent e){
JTextField source = (JTextField)(e.getSource());
source.selectAll();
}
}
Compile and run the application. Click on one of the fields. As you press the mouse down, you will notice that the field is selected. However, when you release the mouse the field is unselected. Run the same application in 1.3 and you will see that it stays selected.
======================================================================
- duplicates
-
JDK-4532513 DefaultCaret requests focus for click and pressed causing input verifier to fire
- Closed