Path: blob/master/test/jdk/javax/swing/JTextPane/JTextPaneDocumentWrapping.java
41152 views
/*1* Copyright (c) 2015, 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/*24* @test25* @key headful26* @bug 813310827* @summary [PIT] Container size is wrong in JEditorPane28* @author Semyon Sadetsky29*/3031import javax.swing.*;32import javax.swing.text.BadLocationException;33import javax.swing.text.SimpleAttributeSet;34import javax.swing.text.html.CSS;35import java.awt.*;3637public class JTextPaneDocumentWrapping {3839private static JFrame frame;40private static JTextPane jTextPane;41private static int position;4243public static void main(String[] args) throws Exception{44SwingUtilities.invokeAndWait(new Runnable() {45@Override46public void run() {47frame = new JFrame();48frame.setUndecorated(true);49frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);50frame.setSize(200, 200);51jTextPane = new JTextPane();52jTextPane.setContentType("text/html");53jTextPane.setText(54"<html><body><b id='test'>Test Test Test Test Test Test " +55"Test Test Test Test Test Test Test Test Test Test " +56"Test Test Test Test Test Test Test Test Test Test" +57"</b></body></html>");58frame.getContentPane().add(jTextPane);59frame.setVisible(true);60}61});62Robot robot = new Robot();63robot.waitForIdle();64robot.delay(200);6566SwingUtilities.invokeAndWait(new Runnable() {67@Override68public void run() {69try {70position = jTextPane.modelToView(100).y;71SimpleAttributeSet wrap = new SimpleAttributeSet();72wrap.addAttribute(CSS.Attribute.WHITE_SPACE, "nowrap");73jTextPane.getStyledDocument()74.setParagraphAttributes(0, 10, wrap, true);75} catch (BadLocationException e) {76e.printStackTrace();77}78}79});80if(position < 40) {81throw new RuntimeException("Text is not wrapped " + position);82}83robot.waitForIdle();84robot.delay(200);85SwingUtilities.invokeAndWait(new Runnable() {86@Override87public void run() {88try {89position = jTextPane.modelToView(100).y;90} catch (BadLocationException e) {91e.printStackTrace();92}93frame.dispose();94}95});96if(position > 20) {97throw new RuntimeException("Text is wrapped " + position);98}99System.out.println("ok");100101}102}103104105