JDK-4328868 : JTextField on a JDialog positions cursor at the end of the text.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.2,1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 2000-04-07
  • Updated: 2001-09-07
  • Resolved: 2001-09-07
Related Reports
Duplicate :  
Duplicate :  
Description

Name: skT45625			Date: 04/07/2000


java version "1.2.2"
Classic VM (build JDK-1.2.2-001, native threads, symcjit)

The behavior of JTextField and where it positions the cursor is different
depending on whether the JTextField is on a JFrame or a JDialog.


Reproduction:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Test extends JFrame
{
   public Test()
   {
      Container contentPane = getContentPane();
      contentPane.setLayout(new GridLayout(4, 1));
      contentPane.add(new JLabel("Press tab - JTextField positions cursor at
start of text"));
      JButton button = new JButton("Dialog");
      contentPane.add(button);
      addTextFields(contentPane);
      button.addActionListener(new ActionListener()
      {
         public void actionPerformed(ActionEvent e)
         {
            TestDialog td = new TestDialog();
            td.show();
         }
      });

   }

   class TestDialog extends JDialog
   {
      public TestDialog()
      {
         setTitle("JDialog");
         Container contentPane = getContentPane();
         contentPane.setLayout(new GridLayout(4, 1));
         contentPane.add(new JLabel("Press tab - JTextField positions cursor at
end of text"));
         contentPane.add(new JButton("dummy"));
         addTextFields(contentPane);
         pack();
      }
   }

   private void addTextFields(Container contentPane)
   {
      TextField text = new TextField("TextField");
      contentPane.add(text);
      JTextField jtext = new JTextField("JTextField");
      contentPane.add(jtext);
   }

   public static void main(String[] args)
   {
      JFrame f = new Test();
      f.setTitle("JFrame");
      f.addWindowListener(new WindowAdapter()
      {
         public void windowClosing(WindowEvent e)
         {
            System.exit(0);
         }
      });

      f.pack();
      f.setVisible(true);
   }
}

###@###.###  2000-04-07
Reproduced in 1.3.0rc3 & 1.4.0beta
(Review ID: 103403) 
======================================================================

Comments
EVALUATION Name: apR10133 Date: 05/22/2001 The bug may be related to 4226384. The root of the problem is JTextComponent.setText() method. ###@###.### ====================================================================== Name: apR10133 Date: 09/07/2001 When the setText() method is called on the EventDispatchThread the cursor is set to the end of text in the textfield. Otherwise, on the main thread, it set to the start of text. This problem doesn't depends on the window type (frame or dialog). Actually this bug is duplicate of 4226384. ###@###.### ======================================================================
24-08-2004

WORK AROUND Name: skT45625 Date: 04/07/2000 JTextField.setCaretPosition(0) ======================================================================
24-08-2004