HeadlessJScrollBar.java revision 10228:b2304c83a42d
1/* 2 * Copyright (c) 2007, 2014, 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 24import javax.swing.*; 25import java.awt.*; 26import java.util.Locale; 27 28/* 29 * @test 30 * @summary Check that JScrollBar constructor and methods do not throw unexpected 31 * exceptions in headless mode 32 * @run main/othervm -Djava.awt.headless=true HeadlessJScrollBar 33 */ 34 35public class HeadlessJScrollBar { 36 public static void main(String args[]) { 37 JScrollBar sb = new JScrollBar(); 38 sb.getAccessibleContext(); 39 sb.isFocusTraversable(); 40 sb.setEnabled(false); 41 sb.setEnabled(true); 42 sb.requestFocus(); 43 sb.requestFocusInWindow(); 44 sb.getPreferredSize(); 45 sb.getMaximumSize(); 46 sb.getMinimumSize(); 47 sb.contains(1, 2); 48 Component c1 = sb.add(new Component(){}); 49 Component c2 = sb.add(new Component(){}); 50 Component c3 = sb.add(new Component(){}); 51 Insets ins = sb.getInsets(); 52 sb.getAlignmentY(); 53 sb.getAlignmentX(); 54 sb.getGraphics(); 55 sb.setVisible(false); 56 sb.setVisible(true); 57 sb.setForeground(Color.red); 58 sb.setBackground(Color.red); 59 for (String font : Toolkit.getDefaultToolkit().getFontList()) { 60 for (int j = 8; j < 17; j++) { 61 Font f1 = new Font(font, Font.PLAIN, j); 62 Font f2 = new Font(font, Font.BOLD, j); 63 Font f3 = new Font(font, Font.ITALIC, j); 64 Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j); 65 66 sb.setFont(f1); 67 sb.setFont(f2); 68 sb.setFont(f3); 69 sb.setFont(f4); 70 71 sb.getFontMetrics(f1); 72 sb.getFontMetrics(f2); 73 sb.getFontMetrics(f3); 74 sb.getFontMetrics(f4); 75 } 76 } 77 sb.enable(); 78 sb.disable(); 79 sb.reshape(10, 10, 10, 10); 80 sb.getBounds(new Rectangle(1, 1, 1, 1)); 81 sb.getSize(new Dimension(1, 2)); 82 sb.getLocation(new Point(1, 2)); 83 sb.getX(); 84 sb.getY(); 85 sb.getWidth(); 86 sb.getHeight(); 87 sb.isOpaque(); 88 sb.isValidateRoot(); 89 sb.isOptimizedDrawingEnabled(); 90 sb.isDoubleBuffered(); 91 sb.getComponentCount(); 92 sb.countComponents(); 93 sb.getComponent(1); 94 sb.getComponent(2); 95 Component[] cs = sb.getComponents(); 96 sb.getLayout(); 97 sb.setLayout(new FlowLayout()); 98 sb.doLayout(); 99 sb.layout(); 100 sb.invalidate(); 101 sb.validate(); 102 sb.remove(0); 103 sb.remove(c2); 104 sb.removeAll(); 105 sb.preferredSize(); 106 sb.minimumSize(); 107 sb.getComponentAt(1, 2); 108 sb.locate(1, 2); 109 sb.getComponentAt(new Point(1, 2)); 110 sb.isFocusCycleRoot(new Container()); 111 sb.transferFocusBackward(); 112 sb.setName("goober"); 113 sb.getName(); 114 sb.getParent(); 115 sb.getPeer(); 116 sb.getGraphicsConfiguration(); 117 sb.getTreeLock(); 118 sb.getToolkit(); 119 sb.isValid(); 120 sb.isDisplayable(); 121 sb.isVisible(); 122 sb.isShowing(); 123 sb.isEnabled(); 124 sb.enable(false); 125 sb.enable(true); 126 sb.enableInputMethods(false); 127 sb.enableInputMethods(true); 128 sb.show(); 129 sb.show(false); 130 sb.show(true); 131 sb.hide(); 132 sb.getForeground(); 133 sb.isForegroundSet(); 134 sb.getBackground(); 135 sb.isBackgroundSet(); 136 sb.getFont(); 137 sb.isFontSet(); 138 Container c = new Container(); 139 c.add(sb); 140 sb.getLocale(); 141 for (Locale locale : Locale.getAvailableLocales()) 142 sb.setLocale(locale); 143 144 sb.getColorModel(); 145 sb.getLocation(); 146 147 boolean exceptions = false; 148 try { 149 sb.getLocationOnScreen(); 150 } catch (IllegalComponentStateException e) { 151 exceptions = true; 152 } 153 if (!exceptions) 154 throw new RuntimeException("IllegalComponentStateException did not occur when expected"); 155 156 sb.location(); 157 sb.setLocation(1, 2); 158 sb.move(1, 2); 159 sb.setLocation(new Point(1, 2)); 160 sb.getSize(); 161 sb.size(); 162 sb.setSize(1, 32); 163 sb.resize(1, 32); 164 sb.setSize(new Dimension(1, 32)); 165 sb.resize(new Dimension(1, 32)); 166 sb.getBounds(); 167 sb.bounds(); 168 sb.setBounds(10, 10, 10, 10); 169 sb.setBounds(new Rectangle(10, 10, 10, 10)); 170 sb.isLightweight(); 171 sb.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); 172 sb.getCursor(); 173 sb.isCursorSet(); 174 sb.inside(1, 2); 175 sb.contains(new Point(1, 2)); 176 sb.isFocusable(); 177 sb.setFocusable(true); 178 sb.setFocusable(false); 179 sb.transferFocus(); 180 sb.getFocusCycleRootAncestor(); 181 sb.nextFocus(); 182 sb.transferFocusUpCycle(); 183 sb.hasFocus(); 184 sb.isFocusOwner(); 185 sb.toString(); 186 sb.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); 187 sb.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 188 sb.setComponentOrientation(ComponentOrientation.UNKNOWN); 189 sb.getComponentOrientation(); 190 } 191} 192