Path: blob/master/test/jdk/javax/swing/JTabbedPane/6495408/bug6495408.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 javax.swing.*;24import java.awt.*;25/*26* @test27* @key headful28* @bug 649540829* @summary REGRESSION: JTabbedPane throws ArrayIndexOutOfBoundsException30* @author Alexander Potochkin31* @run main bug649540832*/3334public class bug6495408 {3536static JTabbedPane tabbedPane;37static JFrame frame;3839public static void main(String[] args) throws Exception {40try {41final Robot robot = new Robot();42robot.setAutoDelay(50);4344SwingUtilities.invokeAndWait(new Runnable() {4546public void run() {47frame = new JFrame();48frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);49tabbedPane = new JTabbedPane();50tabbedPane.setTabPlacement(JTabbedPane.LEFT);51tabbedPane.addTab("Hello", null);52frame.add(tabbedPane);53frame.setSize(400, 400);54frame.setLocationRelativeTo(null);55frame.setVisible(true);56}57});5859robot.waitForIdle();6061final Rectangle d = new Rectangle();62final Point p = new Point();6364for (int i = 0; i < 7; i++) {65SwingUtilities.invokeLater(new Runnable() {6667public void run() {68int tab = tabbedPane.getTabCount() - 1;69Rectangle bounds = tabbedPane.getBoundsAt(tab);70if (bounds != null) {71d.setBounds(bounds);72p.setLocation(d.x + d.width / 2, d.y + d.height / 2);73SwingUtilities.convertPointToScreen(p, tabbedPane);74robot.mouseMove(p.x, p.y + d.height);75tabbedPane.addTab("Hello", null);76}77}78});79}80} finally {81if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());82}83}84}858687