Path: blob/master/test/jdk/javax/swing/JTextArea/JTextAreaWordWrapTest.java
41152 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @key headful25* @bug 821290426* @summary Verifies JTextArea line wrapping using UI scale27* @run main JTextAreaWordWrapTest28*/29import java.awt.BorderLayout;30import java.awt.event.WindowAdapter;31import java.awt.event.WindowEvent;32import java.io.IOException;33import java.net.URISyntaxException;34import javax.swing.JFrame;35import javax.swing.JScrollPane;36import javax.swing.JTextArea;37import javax.swing.ScrollPaneConstants;38import javax.swing.SwingUtilities;3940public class JTextAreaWordWrapTest {4142static JFrame frame;43static JFrame frame1;44static JTextArea textArea;45static JTextArea textArea1;4647public static void doWrapOnTest() {4849frame = new JFrame();50frame.setSize( 720, 300 );51frame.setLayout( new BorderLayout() );5253textArea = new JTextArea();54textArea.setLineWrap( true );55textArea.setWrapStyleWord( true );5657StringBuffer sb = new StringBuffer();58for (int i = 0; i < 100; i++) {59sb.append( "zz zzz zzzz zz zz zz zzz xzzzz zzzzzzzzzzzzzzzzx yyyyyyy tttttttttt sssss hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n" );60}61textArea.setText( sb.toString() );62JScrollPane pane = new JScrollPane( textArea,63ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,64ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );65frame.add( pane, BorderLayout.CENTER );66frame.setVisible( true );6768}6970public static void doWrapOffTest() {71frame1 = new JFrame();72frame1.setSize( 720, 300 );73frame1.setLayout( new BorderLayout() );7475textArea1 = new JTextArea();7677StringBuffer sb1 = new StringBuffer();78for (int i = 0; i < 100; i++) {79sb1.append( "zz zzz zzzz zz zz zz zzz xzzzz zzzzzzzzzzzzzzzzx yyyyyyy tttttttttt sssss hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n" );80}81textArea1.setText( sb1.toString() );82JScrollPane pane1 = new JScrollPane( textArea1,83ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,84ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );85frame1.add( pane1, BorderLayout.CENTER );86frame1.setLocationRelativeTo(null);87frame1.setVisible( true );88}8990public static void main( String[] args ) throws Exception {91System.setProperty( "sun.java2d.uiScale", "1.25" );92try {93SwingUtilities.invokeAndWait(() -> doWrapOnTest());94Thread.sleep(500);95SwingUtilities.invokeAndWait(() -> doWrapOffTest());96Thread.sleep(500);9798SwingUtilities.invokeAndWait(() -> {99100int wraponHeight = textArea.getHeight();101System.out.println("wraponheight " + wraponHeight);102int wrapoffHeight = textArea1.getHeight();103System.out.println("wrapoffheight " + wrapoffHeight);104105if (wraponHeight == wrapoffHeight) {106throw new RuntimeException("JTextArea line wrapping incorrect when using UI scale");107}108});109110} finally {111SwingUtilities.invokeAndWait(() -> frame.dispose());112SwingUtilities.invokeAndWait(() -> frame1.dispose());113}114}115}116117118