Path: blob/master/test/jdk/javax/swing/JTabbedPane/8137169/ScrollableTabbedPaneTest.java
41155 views
/*1* Copyright (c) 2016, 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*/2223/*24* @test25* @key headful26* @bug 813716927* @summary verifies TabbedScrollPane minimum height for all Look and Feels28* @library ../../regtesthelpers29* @build Util30* @run main ScrollableTabbedPaneTest31*/3233import java.awt.Robot;34import javax.swing.JFrame;35import javax.swing.JPanel;36import javax.swing.JTabbedPane;37import javax.swing.SwingConstants;38import javax.swing.SwingUtilities;39import javax.swing.UIManager;40import javax.swing.UnsupportedLookAndFeelException;4142public class ScrollableTabbedPaneTest {4344private static JFrame frame;45private static JTabbedPane pane;46private static Robot robot;47private static volatile String errorString = "";4849public static void main(String[] args) throws Exception {50robot = new Robot();51robot.delay(1000);52UIManager.LookAndFeelInfo[] lookAndFeelArray53= UIManager.getInstalledLookAndFeels();54for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {55executeCase(lookAndFeelItem.getClassName(),56lookAndFeelItem.getName());57}58if (!"".equals(errorString)) {59throw new RuntimeException("Error Log:\n" + errorString);60}61}6263private static void executeCase(String lookAndFeelString, String shortLAF)64throws Exception {65if (tryLookAndFeel(lookAndFeelString)) {66createUI(shortLAF);67stepsToExecute(shortLAF);6869createLeftUI(shortLAF);70stepsToExecute(shortLAF);7172createRightUI(shortLAF);73stepsToExecute(shortLAF);74}75}7677private static void stepsToExecute(String shortLAF) throws Exception {78robot.delay(100);79runTestCase(shortLAF);80robot.delay(1000);81cleanUp();82robot.delay(1000);83}8485private static boolean tryLookAndFeel(String lookAndFeelString)86throws Exception {87try {88UIManager.setLookAndFeel(89lookAndFeelString);9091} catch (UnsupportedLookAndFeelException92| ClassNotFoundException93| InstantiationException94| IllegalAccessException e) {95return false;96}97return true;98}99100private static void cleanUp() throws Exception {101SwingUtilities.invokeAndWait(new Runnable() {102@Override103public void run() {104frame.dispose();105}106});107}108109private static void createUI(final String shortLAF)110throws Exception {111SwingUtilities.invokeAndWait(new Runnable() {112@Override113public void run() {114frame = new JFrame(shortLAF);115frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);116frame.setVisible(true);117pane = new JTabbedPane();118pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);119frame.add(pane);120frame.setSize(500, 500);121}122});123}124private static void createLeftUI(final String shortLAF)125throws Exception {126SwingUtilities.invokeAndWait(new Runnable() {127@Override128public void run() {129frame = new JFrame(shortLAF);130frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);131frame.setVisible(true);132pane = new JTabbedPane();133pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);134pane.setTabPlacement(SwingConstants.LEFT);135frame.add(pane);136frame.setSize(500, 500);137}138});139}140141private static void createRightUI(final String shortLAF)142throws Exception {143SwingUtilities.invokeAndWait(new Runnable() {144@Override145public void run() {146frame = new JFrame(shortLAF);147frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);148frame.setVisible(true);149pane = new JTabbedPane();150pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);151pane.setTabPlacement(SwingConstants.RIGHT);152frame.add(pane);153frame.setSize(500, 500);154}155});156}157158private static void runTestCase(String shortLAF) throws Exception {159SwingUtilities.invokeAndWait(new Runnable() {160@Override161public void run() {162int i = 0;163int value= 0;164do {165String title = "Tab" + (i + 1);166pane.addTab(title, new JPanel());167int tempValue = pane.getMinimumSize().height;168if(value==0) {169value = tempValue;170}171if(value != tempValue) {172String error = "[" + shortLAF173+ "]: [Error]: TabbedScrollPane fails";174errorString += error;175}176177++i;178} while (i < 10);179}180});181}182}183184185186