1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 8137169 26 * @summary verifies TabbedScrollPane minimum height for all Look and Feels 27 * @library ../../regtesthelpers 28 * @build Util 29 * @run main ScrollableTabbedPaneTest 30 */ 31 32 import java.awt.Robot; 33 import javax.swing.JFrame; 34 import javax.swing.JPanel; 35 import javax.swing.JTabbedPane; 36 import javax.swing.SwingConstants; 37 import javax.swing.SwingUtilities; 38 import javax.swing.UIManager; 39 import javax.swing.UnsupportedLookAndFeelException; 40 41 public class ScrollableTabbedPaneTest { 42 43 private static JFrame frame; 44 private static JTabbedPane pane; 45 private static Robot robot; 46 private static volatile String errorString = ""; 47 48 public static void main(String[] args) throws Exception { 49 robot = new Robot(); 50 robot.delay(1000); 51 UIManager.LookAndFeelInfo[] lookAndFeelArray 52 = UIManager.getInstalledLookAndFeels(); 53 for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) { 54 executeCase(lookAndFeelItem.getClassName(), 55 lookAndFeelItem.getName()); 56 } 57 if (!"".equals(errorString)) { 58 throw new RuntimeException("Error Log:\n" + errorString); 59 } 60 } 61 62 private static void executeCase(String lookAndFeelString, String shortLAF) 63 throws Exception { 64 if (tryLookAndFeel(lookAndFeelString)) { 65 createUI(shortLAF); 66 stepsToExecute(shortLAF); 67 68 createLeftUI(shortLAF); 69 stepsToExecute(shortLAF); 70 71 createRightUI(shortLAF); 72 stepsToExecute(shortLAF); 73 } 74 } 75 76 private static void stepsToExecute(String shortLAF) throws Exception { 77 robot.delay(100); 78 runTestCase(shortLAF); 79 robot.delay(1000); 80 cleanUp(); 81 robot.delay(1000); 82 } 83 84 private static boolean tryLookAndFeel(String lookAndFeelString) 85 throws Exception { 86 try { 87 UIManager.setLookAndFeel( 88 lookAndFeelString); 89 90 } catch (UnsupportedLookAndFeelException 91 | ClassNotFoundException 92 | InstantiationException 93 | IllegalAccessException e) { 94 return false; 95 } 96 return true; 97 } 98 99 private static void cleanUp() throws Exception { 100 SwingUtilities.invokeAndWait(new Runnable() { 101 @Override 102 public void run() { 103 frame.dispose(); 104 } 105 }); 106 } 107 108 private static void createUI(final String shortLAF) 109 throws Exception { 110 SwingUtilities.invokeAndWait(new Runnable() { 111 @Override 112 public void run() { 113 frame = new JFrame(shortLAF); 114 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 115 frame.setVisible(true); 116 pane = new JTabbedPane(); 117 pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 118 frame.add(pane); 119 frame.setSize(500, 500); 120 } 121 }); 122 } 123 private static void createLeftUI(final String shortLAF) 124 throws Exception { 125 SwingUtilities.invokeAndWait(new Runnable() { 126 @Override 127 public void run() { 128 frame = new JFrame(shortLAF); 129 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 130 frame.setVisible(true); 131 pane = new JTabbedPane(); 132 pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 133 pane.setTabPlacement(SwingConstants.LEFT); 134 frame.add(pane); 135 frame.setSize(500, 500); 136 } 137 }); 138 } 139 140 private static void createRightUI(final String shortLAF) 141 throws Exception { 142 SwingUtilities.invokeAndWait(new Runnable() { 143 @Override 144 public void run() { 145 frame = new JFrame(shortLAF); 146 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 147 frame.setVisible(true); 148 pane = new JTabbedPane(); 149 pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 150 pane.setTabPlacement(SwingConstants.RIGHT); 151 frame.add(pane); 152 frame.setSize(500, 500); 153 } 154 }); 155 } 156 157 private static void runTestCase(String shortLAF) throws Exception { 158 SwingUtilities.invokeAndWait(new Runnable() { 159 @Override 160 public void run() { 161 int i = 0; 162 int value= 0; 163 do { 164 String title = "Tab" + (i + 1); 165 pane.addTab(title, new JPanel()); 166 int tempValue = pane.getMinimumSize().height; 167 if(value==0) { 168 value = tempValue; 169 } 170 if(value != tempValue) { 171 String error = "[" + shortLAF 172 + "]: [Error]: TabbedScrollPane fails"; 173 errorString += error; 174 } 175 176 ++i; 177 } while (i < 10); 178 } 179 }); 180 } 181 } 182