-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.0
-
x86
-
windows_nt
Name: pa48320 Date: 11/20/2001
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-4546077 REGRESSION: JEditor pane focus problems with HTML components (submit)
- Closed
- relates to
-
JDK-4532513 DefaultCaret requests focus for click and pressed causing input verifier to fire
- Closed