On 23-Mar-19 5:02 AM, Sergey Bylokhov wrote:
On 21/03/2019 22:34, Prasanta Sadhukhan wrote:
Thanks for your review. textarea.getLineCount() returns same number for both correct and broken wrap so it cannot be used for test automation...

Then probably it can be checked by the visibility of the horizontal scroll bar? If you set the scrollbar policy as HORIZONTAL_SCROLLBAR_AS_NEEDED then you can check is it visible(wrap-off) or is it invisible(wrap-on). Or you can check the height of the text area, which is different when wrap on/off.

Thanks Sergey for the pointer. But horizontal scrollbar is not visible for both correct and broken wrap if scrollbar policy is set to HORIZONTAL_SCROLLBAR_AS_NEEDED. Also, the textArea.getHeight() is same for both textArea.setWrapStyleWord( true ) and not. Attached is the automated testcase I tried.

Regards
Prasanta
Regards
Prasanta
On 21-Mar-19 4:24 AM, Sergey Bylokhov wrote:
Hi, Prasanta.

The change looks fine, but probably the test can be automated? I guess when "wrap" works properly you should get more lines in the text area, than in case of broken "wrap"?

On 19/03/2019 00:03, Prasanta Sadhukhan wrote:
Hi All,

Please review a fix for an issue where it is seen that
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)

It is a regression of JDK-8132119: Provide public API for text related methods in SwingUtilities2 where many public text related API was added catering to floating point hidpi scale. This issue happened because of that as the public Utilities.getBreakLocation() API, used to determine where to break the given text, is using non-floating point methods.

Proposed fix is to make sure correct getBreakLocation() method is called and not the deprecated(integer based) one and also the floating point based getBreakLocation() API uses floating point API based calculations.

Bug: https://bugs.openjdk.java.net/browse/JDK-8212904
webrev: http://cr.openjdk.java.net/~psadhukhan/8212904/webrev.0/

Regards
Prasanta






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;
import javax.swing.SwingUtilities;

public class JTextAreaTest {

    static JFrame frame;
    static JFrame frame1;
    static int wraponHeight;
    static int wrapoffHeight;

    public static void doWrapOnTest() {

        frame = new JFrame();
        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_AS_NEEDED );
        frame.add( pane, BorderLayout.CENTER );
        frame.setVisible( true );

        wraponHeight = textArea.getHeight();
        System.out.println("wraponheight " + wraponHeight);
    }

    public static void doWrapOffTest() {
        frame1 = new JFrame();
        frame1.setSize( 720, 300 );
        frame1.setLayout( new BorderLayout() );

        JTextArea textArea1 = new JTextArea();
        textArea1.setLineWrap( true );
        
        StringBuffer sb1 = new StringBuffer();
        for (int i = 0; i < 100; i++) {
            sb1.append( "zz zzz zzzz zz zz zz zzz xzzzz zzzzzzzzzzzzzzzzx 
yyyyyyy tttttttttt sssss hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n" 
);
        }
        textArea1.setText( sb1.toString() );
        JScrollPane pane1 = new JScrollPane( textArea1, 
                                             
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, 
                                             
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );
        frame1.add( pane1, BorderLayout.CENTER );
        frame1.setLocationRelativeTo(null);
        frame1.setVisible( true );
        wrapoffHeight = textArea1.getHeight();
        System.out.println("wrapoffheight " + wrapoffHeight);
    }

    public static void main( String[] args ) throws Exception {
        System.setProperty( "sun.java2d.uiScale", "1.25" );
        try {
            SwingUtilities.invokeAndWait(() -> doWrapOnTest());
            Thread.sleep(2000);
            SwingUtilities.invokeAndWait(() -> doWrapOffTest());
            Thread.sleep(2000);

            if (wraponHeight == wrapoffHeight) {
                throw new RuntimeException("JTextArea line wrapping incorrect 
when using UI scale");
            }
        } finally {
            SwingUtilities.invokeAndWait(() -> frame.dispose());
            SwingUtilities.invokeAndWait(() -> frame1.dispose());
        }
    }
} 

Reply via email to