Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTabbedPane/4361477/bug4361477.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.*;24import java.awt.event.*;25import javax.swing.*;26import javax.swing.event.*;2728/*29* @test30* @bug 436147731* @summary JTabbedPane throws ArrayOutOfBoundsException32* @author Oleg Mokhovikov33* @run main bug436147734*/35public class bug4361477 {3637static JTabbedPane tabbedPane;38volatile static boolean bStateChanged = false;39volatile static Rectangle bounds;4041public static void main(String args[]) throws Exception {4243Robot robot = new Robot();44robot.setAutoDelay(50);4546SwingUtilities.invokeAndWait(new Runnable() {4748@Override49public void run() {50createAndShowUI();51}52});5354robot.waitForIdle();5556SwingUtilities.invokeAndWait(new Runnable() {5758@Override59public void run() {60bounds = tabbedPane.getUI().getTabBounds(tabbedPane, 0);61}62});6364Point location = bounds.getLocation();65SwingUtilities.convertPointToScreen(location, tabbedPane);66robot.mouseMove(location.x + 1, location.y + 1);67robot.mousePress(InputEvent.BUTTON1_MASK);68robot.mouseRelease(InputEvent.BUTTON1_MASK);6970if (!bStateChanged) {71throw new RuntimeException("Tabbed pane state is not changed");72}73}7475static void createAndShowUI() {7677final JFrame frame = new JFrame();78tabbedPane = new JTabbedPane();79tabbedPane.add("Tab0", new JPanel());80tabbedPane.add("Tab1", new JPanel());81tabbedPane.add("Tab2", new JPanel());82tabbedPane.setSelectedIndex(2);83tabbedPane.addChangeListener(new ChangeListener() {8485public void stateChanged(final ChangeEvent pick) {86bStateChanged = true;87if (tabbedPane.getTabCount() == 3) {88tabbedPane.remove(2);89}90}91});9293frame.getContentPane().add(tabbedPane);94frame.setSize(300, 200);95frame.setVisible(true);96}97}9899100