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

JTextField Caret Missing when enabling & disabling

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.4.0
    • client-libs
    • tiger
    • x86
    • windows_2000



      Name: jk109818 Date: 05/06/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      Microsoft Windows 2000 [Version 5.00.2195]


      A DESCRIPTION OF THE PROBLEM :
      If you have a JButton and a JTextField on a panel in that
      order and you click on the JButton which causes it to
      become disabled and THEN the JTextField to become
      disabled. Then if programmatically you enable both of
      them, you cannot get the caret to appear in the JTextField,
      even though the JTextField has focus and if you begin
      typing characters will show up in the JTextField.

      There is a workaround (see workaround section).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and run program
      2. Click on Button 3
      3. Wait 5 seconds for thread to complete
      4. Click on the textfield to have it gain focus
      5. Notice no caret is displayed in the textfield and you
      also cannot select any of the text

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      After the button and textfield become enabled if the
      textfield gets focus it should contain a blinking caret.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No stack trace or error generated.

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class Test extends JFrame implements ActionListener {

      private JButton btn1 = new JButton("Button 1");
      private JButton btn2 = new JButton("Button 2");
      private JButton btn3 = new JButton("Button 3");
      private JTextField t = new JTextField("some text", 10);
      private JPanel pnl = new JPanel();

      public Test() {
      t.setEditable(true);
      setSize(400,400);
      Container c = getContentPane();
      pnl.add(btn1);
      btn3.addActionListener(this);
      pnl.add(btn2);
      pnl.add(btn3);
      pnl.add(t);
      c.add(pnl);
      }

          public void actionPerformed(ActionEvent ae) {
              System.out.println("action command is " + ae.getActionCommand());
              if (ae.getActionCommand().equals("Button 3")) {
                  btn3.setEnabled(false) ;
                  t.setEnabled(false);
                  Thread t = new myThread();
                  t.start();
              }
          }

          class myThread extends Thread {
              public void run() {
                  try {
                      Thread.sleep(5000);
                      btn3.setEnabled(true);
                      t.setEnabled(true);
                  } catch (Throwable t) {
                      System.out.println(t.getMessage());
                  }
              }
          }

      public static void main(String[] args) {
      Test t = new Test();
      try {
      UIManager.setLookAndFeel
                          (UIManager.getSystemLookAndFeelClassName());
                  SwingUtilities.updateComponentTreeUI(t);
      } catch (Throwable ex) {
      System.out.println(ex.getMessage());
      }
      t.show();
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Disable the JTextField THEN the JButton in that order and
      it will work.
      (Review ID: 146233)
      ======================================================================

            naasunw Naa Naa (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: