JDK-4529881 : JTextField selections gathered in focusGained are lost on mouse up
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-11-20
  • Updated: 2001-12-15
  • Resolved: 2001-12-15
Related Reports
Duplicate :  
Relates :  
Description

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.
======================================================================

Comments
WORK AROUND Name: pa48320 Date: 11/20/2001 unknown. ======================================================================
11-06-2004

EVALUATION This is actually a duplicate of 4532513. ###@###.### 2002-03-04
04-03-2002