-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b56
-
x86
-
windows_2000, windows_xp
Name: gm110360 Date: 02/08/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
JTextArea.setRows() is supposed to allow you to set an approximate height for the JTextArea, presumably as a function of the height of its current Font. This normally causes a JTextArea that's not in a JScrollPane to have a preferredSize that's independent of its text contents.
In the example program below, note that when the JTextArea contains no text, it seems to behave properly.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test case program given below under both 1.5.0 beta, and any previous version, and you'll see how the JTextArea's getPreferredSize() is returning a height far greater than what it should be under 1.5.0.
By the way, on the dropdown for "Regression" listed above, it's not wide enough for me to read what JDK I picked (I'm using IE.) But the code below was tested worked properly under 1.3.1 and 1.4.2._03.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'm expecting to see a small JFrame containing a JTextArea about 35 columns wide and 12 text rows high.
ACTUAL -
I'm seeing a JFrame containing a JTextArea about 35 columns wide, and higher than my entire screen, which is in 1280 by 1024 resolution.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
public class JTextAreaBug {
static String message =
"The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog.\n\n"
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog.\n\n"
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog. "
+ "The quick brown fox jumps over the lazy dog.\n\n";
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(3);
JPanel cp = new JPanel();
cp.setLayout(new BorderLayout());
JTextArea jt = new JTextArea();
// if you comment out this line, the program
// seems to behave properly.
jt.setText(message);
jt.setLineWrap(true);
jt.setWrapStyleWord(true);
jt.setColumns(35);
jt.setRows(12);
cp.add(jt, BorderLayout.CENTER);
frame.setContentPane(cp);
frame.pack();
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I have none.
Release Regression From : 1.4.2
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Incident Review ID: 237636)
======================================================================
- duplicates
-
JDK-4986141 "DeskTop Integration" dialog size is more then what it is needed.
- Closed
- relates to
-
JDK-4446522 JTextArea.getPreferredSize() incorrect when line wrapping is used
- Resolved
-
JDK-5053608 Should investigate extension to LayoutManagers to support flexible components
- Open