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