-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.1.7, 1.2.2, 1.3.0
-
generic, x86
-
generic, windows_nt
Name: dbT83986 Date: 04/02/99
When I call JTextField.setText() with a string that is too long to fit in the JTextField, the text is Left Justified if I make the call before
event handling has started. But if the call to setText() originates from the EventDispatchThread, then if the text is too long, it is
Right Justified even if I call setHorizontalAlignment(JTextField.LEFT) or call setScrollOffset(0).
I'm just guessing that the EventDispatchThread is significant. That's the only difference I can detect between the 2 setText() calls
in the program that follows.
The code below isolates the behavior I'm seeing in a very large panel rendering application. This bug makes some fields very
difficult to read.
=================================================================
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RJText extends JFrame
{
private JTextField text = new JTextField();
String[] strings = {"What will happen when the text is too long to fit??", "This fits"};
private int setTextCount = 1;
public RJText()
{
super("Text Justification Test");
Container cp = getContentPane();
cp.setLayout(null);
text.setHorizontalAlignment(JTextField.LEFT);
cp.add(text);
text.setBounds(20, 20, 150, 19);
JButton button = new JButton("Click to setText");
cp.add(button);
button.setBounds(20, 100, 190, 20);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// This will cause left truncation when we use strings[0]
text.setText(strings[setTextCount % 2]);
// next line has no effect
text.setScrollOffset(0);
setTextCount++;
}
});
setSize(300, 200);
setVisible(true);
// This won't truncate on the left
text.setText(strings[0]);
}
public static void main(String[] args)
{
new RJText();
}
}
(Review ID: 56151)
======================================================================
- duplicates
-
JDK-4328868 JTextField on a JDialog positions cursor at the end of the text.
-
- Closed
-
- relates to
-
JDK-4343970 JTextArea scrolls to end of text when displayed via JButton/JMenuItem
-
- Closed
-
-
JDK-4424708 JPasswordField cursor placed incorrectly after setText("")
-
- Closed
-