JDK-4992455 : REGRESSION: TextArea does not wrap text in JDK 1.5 as JDK 1.4.x
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2004-02-11
  • Updated: 2015-09-04
  • Resolved: 2004-02-27
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 b41Fixed
Related Reports
Relates :  
Description

Name: gm110360			Date: 02/10/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 :
Linux 2.4.22-1.2149.nptl

A DESCRIPTION OF THE PROBLEM :
If a TextArea is created in JDK 1.5 for linux without a horizontal scrollbar, the text it is initialized with will not have any line breaks inserted if the text length exceeds the width of the TextArea. All other JDKs, including JDK 1.5 for windows, will insert line breaks in the appropriate locations to ensure all of the text is visible.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Make a TextArea with an initial string longer than the width of the area and without a horizontal scrollbar:

TextArea ta = new TextArea("This text should be wrapped",  3, 10,                                                                                             TextArea.SCROLLBARS_VERTICAL_ONLY);


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -

Line breaks should appear between text / should and be / wrapped
ACTUAL -
No line breaks are present and the end of the line is not visible

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;

public class TextAreaBug extends Frame
{
    public static void main(String [] args)    {  new TextAreaBug().show();    }

    TextAreaBug()
    {
        super("TextArea Bug");
        this.setBounds(50, 50, 400, 400);
        this.setLayout(new FlowLayout());
        this.add(new TextArea("This text should be wrapped", 5, 10,
                              TextArea.SCROLLBARS_VERTICAL_ONLY));
        this.pack();
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :

Insert line breaks manually and hope the appropriate break locations are chosen.

Release Regression From : 1.4.2_03
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: 238062) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b41 tiger-beta2
14-06-2004

SUGGESTED FIX Name: dkR10074 Date: 02/18/2004 ------- XTextAreaPeer.java ------- *** //C/Tools/forte4j/platform/intel-win/bin/util/tmp/sccs.002052 Wed Feb 18 15:30:10 2004 --- XTextAreaPeer.java Wed Feb 18 15:25:58 2004 *************** *** 96,101 **** --- 96,102 ---- firstChangeSkipped = false; String text = ((TextArea)target).getText(); jtext = new AWTTextArea(text, this); + jtext.setWrapStyleWord(true); jtext.getDocument().addDocumentListener(jtext); XToolkit.specialPeerMap.put(jtext,this); jtext.enableInputMethods(true); *************** *** 157,166 **** --- 158,169 ---- void setScrollBarVisibility() { int visibility = ((TextArea)target).getScrollbarVisibility(); + jtext.setLineWrap(false); if (visibility == TextArea.SCROLLBARS_NONE) { textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); + jtext.setLineWrap(true); } else if (visibility == TextArea.SCROLLBARS_BOTH) { *************** *** 170,175 **** --- 173,179 ---- else if (visibility == TextArea.SCROLLBARS_VERTICAL_ONLY) { textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + jtext.setLineWrap(true); } else if (visibility == TextArea.SCROLLBARS_HORIZONTAL_ONLY) { textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); ###@###.### 2004-02-18 ======================================================================
18-02-2004

EVALUATION Name: dkR10074 Date: 02/16/2004 Here are two excerpts from Javadoc that we are interested in: 1. About line wrapping property. "JTextArea has a bound property for line wrapping that controls whether or not it will wrap lines. By default, the line wrapping property is set to false (not wrapped)." 2. About wrapping style property. "If set to true the lines will be wrapped at word boundaries (whitespace) if they are too long to fit within the allocated width. If set to false, the lines will be wrapped at character boundaries. By default this property is false." Since we use JTextArea in XAWT as the TextArea component we should use the following code if we want to wrap lines at word boundaries: jtext.setLineWrap(true); jtext.setWrapStyleWord(true); It is a trivial low-risk change of the source code. ###@###.### 2004-02-16 ======================================================================
16-02-2004