Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8212904

JTextArea line wrapping incorrect when using UI scale

    XMLWordPrintable

Details

    • b127
    • 9
    • b15
    • x86_64
    • generic

    Backports

      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


        Attachments

          Issue Links

            Activity

              People

                psadhukhan Prasanta Sadhukhan
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: