Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTabbedPane/7024235/Test7024235.java
38855 views
/*1* Copyright (c) 2013, 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*/2223import java.awt.BorderLayout;2425import java.awt.Container;26import java.awt.Rectangle;27import java.awt.Toolkit;2829import javax.swing.JButton;30import javax.swing.JCheckBox;31import javax.swing.JTabbedPane;3233import javax.swing.JFrame;34import javax.swing.SwingUtilities;35import javax.swing.UIManager;36import javax.swing.UIManager.LookAndFeelInfo;3738/*39* @test40* @bug 702423541* @summary Tests JFrame.pack() with the JTabbedPane42* @library ../../../../lib/testlibrary/43* @build ExtendedRobot44* @author Sergey Malenkov45* @run main Test702423546*/4748public class Test7024235 implements Runnable {4950private static final boolean AUTO = null != System.getProperty("test.src", null);5152public static void main(String[] args) throws Exception {53Test7024235 test = new Test7024235();54for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {55UIManager.setLookAndFeel(info.getClassName());5657test.test();58try {59ExtendedRobot robot = new ExtendedRobot();60robot.waitForIdle(1000);61}catch(Exception ex) {62ex.printStackTrace();63throw new Error("Unexpected Failure");64}65test.test();66}67}6869private volatile JTabbedPane pane;70private volatile boolean passed;7172public void run() {73if (this.pane == null) {74this.pane = new JTabbedPane();75this.pane.addTab("1", new Container());76this.pane.addTab("2", new JButton());77this.pane.addTab("3", new JCheckBox());7879JFrame frame = new JFrame();80frame.add(BorderLayout.WEST, this.pane);81frame.pack();82frame.setVisible(true);8384test("first");85}86else {87test("second");88if (this.passed || AUTO) { // do not close a frame for manual review89SwingUtilities.getWindowAncestor(this.pane).dispose();90}91this.pane = null;92}93}9495private void test() throws Exception {96SwingUtilities.invokeAndWait(this);97if (!this.passed && AUTO) { // error reporting only for automatic testing98throw new Error("TEST FAILED");99}100}101102private void test(String step) {103this.passed = true;104for (int index = 0; index < this.pane.getTabCount(); index++) {105Rectangle bounds = this.pane.getBoundsAt(index);106int centerX = bounds.x + bounds.width / 2;107int centerY = bounds.y + bounds.height / 2;108int actual = this.pane.indexAtLocation(centerX, centerY);109if (index != actual) {110System.out.println("name = " + UIManager.getLookAndFeel().getName());111System.out.println("step = " + step);112System.out.println("index = " + index);113System.out.println("bounds = " + bounds);114System.out.println("indexAtLocation(" + centerX + "," + centerX + ") returns " + actual);115this.passed = false;116}117}118}119}120121122