JDK-4990877 : REGRESSION: JTextArea.setRows() broken.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2004-02-09
  • Updated: 2004-06-14
  • Resolved: 2004-06-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b56Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description

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

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b56 tiger-rc
08-07-2004

EVALUATION On 1.4.2 only two paragraphs out of three are visible. On 1.5 all text is displayed. Name: anR10225 Date: 03/10/2004 The bug is introduced by the fix for the 4446522. It seems this fix should be rolled back for Tiger, since it may be the reason of many regressions. The bug 4446522 should be reopened and fixed in other way. ======================================================================
08-07-2004

WORK AROUND Doing two pack() in row does acceptable layout -- *** JTextAreaBug.java 2004/03/17 01:36:22 1.1 --- JTextAreaBug.java 2004/03/17 01:36:29 *************** *** 48,53 **** --- 48,54 ---- cp.add(jt, BorderLayout.CENTER); frame.setContentPane(cp); frame.pack(); + frame.pack(); frame.setVisible(true); } -- ###@###.### 2004-03-16
16-03-2004