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