Path: blob/master/test/jdk/javax/swing/JTabbedPane/4361477/bug4361477.java
41155 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* @key headful31* @bug 436147732* @summary JTabbedPane throws ArrayOutOfBoundsException33* @author Oleg Mokhovikov34* @run main bug436147735*/36public class bug4361477 {3738static JTabbedPane tabbedPane;39volatile static boolean bStateChanged = false;40volatile static Rectangle bounds;41static JFrame frame;4243public static void main(String args[]) throws Exception {44try {4546Robot robot = new Robot();47robot.setAutoDelay(50);4849SwingUtilities.invokeAndWait(new Runnable() {5051@Override52public void run() {53createAndShowUI();54}55});5657robot.waitForIdle();5859SwingUtilities.invokeAndWait(new Runnable() {6061@Override62public void run() {63bounds = tabbedPane.getUI().getTabBounds(tabbedPane, 0);64}65});6667Point location = bounds.getLocation();68SwingUtilities.convertPointToScreen(location, tabbedPane);69robot.mouseMove(location.x + 1, location.y + 1);70robot.mousePress(InputEvent.BUTTON1_MASK);71robot.mouseRelease(InputEvent.BUTTON1_MASK);7273if (!bStateChanged) {74throw new RuntimeException("Tabbed pane state is not changed");75}76} finally {77if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());78}79}8081static void createAndShowUI() {8283frame = new JFrame();84tabbedPane = new JTabbedPane();85tabbedPane.add("Tab0", new JPanel());86tabbedPane.add("Tab1", new JPanel());87tabbedPane.add("Tab2", new JPanel());88tabbedPane.setSelectedIndex(2);89tabbedPane.addChangeListener(new ChangeListener() {9091public void stateChanged(final ChangeEvent pick) {92bStateChanged = true;93if (tabbedPane.getTabCount() == 3) {94tabbedPane.remove(2);95}96}97});9899frame.getContentPane().add(tabbedPane);100frame.setSize(300, 200);101frame.setVisible(true);102}103}104105106