JDK-8212904 : JTextArea line wrapping incorrect when using UI scale
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 9,11,12
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-10-18
  • Updated: 2022-06-20
  • Resolved: 2019-03-29
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.
JDK 11 JDK 13
11.0.17Fixed 13 b15Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10

openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

A DESCRIPTION OF THE PROBLEM :
Line wrapping of JTextArea doen't work correctly if you set wrapStyleWord = true and you use a UI scale (either by setting "sun.java2d.uiScale" or by setting display scale of Windows). In the example below the last long word ("hhhh...") is not wrapped although there is not enough line space. If you use wrapStyleWord = false or no UI scale than it works.

REGRESSION : Last worked in version 8u181

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute example below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Last word "hhhh...." is wrapped to the next line.
ACTUAL -
A part of the last word is hidden.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URISyntaxException;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;

public class JTextAreaTest {

    public static void main( String[] args ) throws IOException, URISyntaxException {
        System.setProperty( "sun.java2d.uiScale", "1.25" );

        JFrame frame = new JFrame();
        frame.addWindowListener( new WindowAdapter() {
            @Override
            public void windowClosing( WindowEvent e ) {
                System.exit( 0 );
            }
        } );
        frame.setSize( 720, 300 );
        
        frame.setLayout( new BorderLayout() );
        
        JTextArea textArea = new JTextArea();
        textArea.setLineWrap( true );
        textArea.setWrapStyleWord( true );
        
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 100; i++) {
            sb.append( "zz zzz zzzz zz zz zz zzz xzzzz zzzzzzzzzzzzzzzzx yyyyyyy tttttttttt sssss hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n" );
        }
        textArea.setText( sb.toString() );
        JScrollPane pane = new JScrollPane( textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS );
        frame.add( pane, BorderLayout.CENTER );
        frame.setVisible( true );
    }
}

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

FREQUENCY : always



Comments
Fix request (11u) - Justification: The fix for a regression introduced by the JDK-8132119 in JDK 9 - Parity with 11.0.15.0.1 - Risk Analysis: Low - Testing: The new test fails before the fix and passes after. The :java_desktop tests are green. - Review https://github.com/openjdk/jdk11u-dev/pull/1143
12-06-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/1143 Date: 2022-06-10 23:04:54 +0000
10-06-2022

URL: http://hg.openjdk.java.net/jdk/jdk/rev/35975113d5d8 User: psadhukhan Date: 2019-04-03 08:46:47 +0000
03-04-2019

URL: http://hg.openjdk.java.net/jdk/client/rev/35975113d5d8 User: psadhukhan Date: 2019-03-29 04:41:20 +0000
29-03-2019

Regression from jdk9b127 onwards due to 8132119: Provide public API for text related methods in SwingUtilities2
18-03-2019

Issue is reproducible and regression introduced in JDK 9+127. Windows 10, 64-bit JDK results -------------------------------------- 8u192 : Pass 9+126 : Pass 9+127 : Fail <-- Regression 11.0.1+13 : Fail 12-ea+15 : Fail --------------------------------------
24-10-2018