Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4529881

JTextField selections gathered in focusGained are lost on mouse up

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs



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

            idk Igor Kushnirskiy (Inactive)
            pallenba Peter Allenbach (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: