Path: blob/master/test/jdk/javax/swing/JLayer/6824395/bug6824395.java
41155 views
/*1* Copyright (c) 2009, 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* @summary Checks that JLayer inside JViewport works is correctly laid out27* @author Alexander Potochkin28* @library /lib/client/29* @build ExtendedRobot30* @run main bug682439531*/32333435import javax.swing.*;36import javax.swing.plaf.LayerUI;37import java.awt.*;3839public class bug6824395 {4041static JScrollPane scrollPane;42static JFrame frame;4344public static void main(String[] args) throws Exception {45try {46SwingUtilities.invokeAndWait(new Runnable() {47public void run() {48frame = new JFrame("testing");49frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);5051JEditorPane editorPane = new JEditorPane();52String str = "hello\n";53for(int i = 0; i<5; i++) {54str += str;55}5657editorPane.setText(str);5859JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);60LayerUI<JComponent> layerUI = new LayerUI<JComponent>();61editorPaneLayer.setUI(layerUI);6263scrollPane = new JScrollPane(editorPaneLayer);64scrollPane.setViewportBorder(null);65scrollPane.setPreferredSize(new Dimension(200, 250));66frame.add(scrollPane);6768frame.setSize(200, 200);69frame.pack();70frame.setVisible(true);71}72});73try {74ExtendedRobot robot = new ExtendedRobot();75robot.waitForIdle(300);76}catch(Exception ex) {77ex.printStackTrace();78throw new Error("Unexpected Failure");79}80SwingUtilities.invokeAndWait(new Runnable() {81public void run() {82if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {83throw new RuntimeException("Wrong component's width!");84}85}86});87} finally {88if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());89}90}91}929394