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