Path: blob/master/test/jdk/javax/swing/JTabbedPane/7161568/bug7161568.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*/22import java.awt.*;23import javax.swing.*;24import java.awt.event.*;2526/**27* @test28* @key headful29* @bug 716156830* @author Alexander Scherbatiy31* @summary Tests that navigating tabs in the JTAbbedPane does not throw NPE32* @run main bug716156833*/34public class bug7161568 {3536private static final int N = 50;37private static JTabbedPane tabbedPane;38private static JFrame frame;3940public static void main(String[] args) throws Exception {41UIManager.put("TabbedPane.selectionFollowsFocus", Boolean.FALSE);4243try {44Robot robot = new Robot();45robot.setAutoDelay(50);4647SwingUtilities.invokeAndWait(new Runnable() {4849@Override50public void run() {51createAndShowUI();52}53});5455robot.waitForIdle();5657SwingUtilities.invokeAndWait(new Runnable() {5859@Override60public void run() {61tabbedPane.requestFocus();62}63});6465robot.waitForIdle();6667for (int i = 0; i < N; i++) {68robot.keyPress(KeyEvent.VK_LEFT);69robot.keyRelease(KeyEvent.VK_LEFT);70robot.waitForIdle();71}72} finally {73if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());74}75}7677static void createAndShowUI() {78frame = new JFrame("Test");79frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);80frame.setSize(100, 100);8182tabbedPane = new JTabbedPane();8384for (int i = 0; i < N; i++) {85tabbedPane.addTab("Tab: " + i, new JLabel("Test"));86}8788tabbedPane.setSelectedIndex(0);8990frame.getContentPane().add(tabbedPane);91frame.setVisible(true);92}93}949596