Path: blob/master/test/jdk/javax/swing/JTabbedPane/7024235/Test7024235.java
41153 views
/*1* Copyright (c) 2013, 2020, 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;24import java.awt.Container;25import java.awt.Rectangle;26import java.awt.Robot;2728import javax.swing.JButton;29import javax.swing.JCheckBox;30import javax.swing.JFrame;31import javax.swing.JTabbedPane;32import javax.swing.SwingUtilities;33import javax.swing.UIManager;34import javax.swing.UIManager.LookAndFeelInfo;3536/*37* @test38* @key headful39* @bug 702423540* @summary Tests JFrame.pack() with the JTabbedPane41* @run main Test702423542*/4344public class Test7024235 implements Runnable {4546private static final boolean AUTO = null != System.getProperty("test.src", null);4748public static void main(String[] args) throws Exception {49Test7024235 test = new Test7024235();50for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {51String className = info.getClassName();52System.out.println("className = " + className);53UIManager.setLookAndFeel(className);5455test.test();56try {57Robot robot = new Robot();58robot.waitForIdle();59robot.delay(1000);60}catch(Exception ex) {61ex.printStackTrace();62throw new Error("Unexpected Failure");63}64test.test();65}66}6768private volatile JTabbedPane pane;69private volatile boolean passed;7071public void run() {72if (this.pane == null) {73this.pane = new JTabbedPane();74this.pane.addTab("1", new Container());75this.pane.addTab("2", new JButton());76this.pane.addTab("3", new JCheckBox());7778JFrame frame = new JFrame();79frame.add(BorderLayout.WEST, this.pane);80frame.pack();81frame.setLocationRelativeTo(null);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);106if (bounds == null) {107continue;108}109int centerX = bounds.x + bounds.width / 2;110int centerY = bounds.y + bounds.height / 2;111int actual = this.pane.indexAtLocation(centerX, centerY);112if (index != actual) {113System.out.println("name = " + UIManager.getLookAndFeel().getName());114System.out.println("step = " + step);115System.out.println("index = " + index);116System.out.println("bounds = " + bounds);117System.out.println("indexAtLocation(" + centerX + "," + centerX + ") returns " + actual);118this.passed = false;119}120}121}122}123124125