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