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