Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JLayer/6824395/bug6824395.java
38918 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* @summary Checks that JLayer inside JViewport works is correctly laid out26* @author Alexander Potochkin27* @library ../../../../lib/testlibrary/28* @build ExtendedRobot29* @run main bug682439530*/31323334import javax.swing.*;35import javax.swing.plaf.LayerUI;36import java.awt.*;3738public class bug6824395 {3940static JScrollPane scrollPane;4142public static void main(String[] args) throws Exception {43SwingUtilities.invokeAndWait(new Runnable() {44public void run() {45JFrame frame = new JFrame("testing");46frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4748JEditorPane editorPane = new JEditorPane();49String str = "hello\n";50for(int i = 0; i<5; i++) {51str += str;52}5354editorPane.setText(str);5556JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);57LayerUI<JComponent> layerUI = new LayerUI<JComponent>();58editorPaneLayer.setUI(layerUI);5960scrollPane = new JScrollPane(editorPaneLayer);6162scrollPane.setPreferredSize(new Dimension(200, 250));63frame.add(scrollPane);6465frame.setSize(200, 200);66frame.pack();67frame.setVisible(true);68}69});70try {71ExtendedRobot robot = new ExtendedRobot();72robot.waitForIdle(300);73}catch(Exception ex) {74ex.printStackTrace();75throw new Error("Unexpected Failure");76}77SwingUtilities.invokeAndWait(new Runnable() {78public void run() {79if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {80throw new RuntimeException("Wrong component's width!");81}82}83});84}85}868788