Path: blob/master/test/jdk/javax/swing/Headless/HeadlessJMenuBar.java
41152 views
/*1* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.swing.*;24import java.awt.*;25import java.util.Locale;2627/*28* @test29* @summary Check that JMenuBar constructor and methods do not throw unexpected30* exceptions in headless mode31* @run main/othervm -Djava.awt.headless=true HeadlessJMenuBar32*/3334public class HeadlessJMenuBar {35public static void main(String args[]) {36JMenuBar mb = new JMenuBar();37mb.getAccessibleContext();38mb.isFocusTraversable();39mb.setEnabled(false);40mb.setEnabled(true);41mb.requestFocus();42mb.requestFocusInWindow();43mb.getPreferredSize();44mb.getMaximumSize();45mb.getMinimumSize();46mb.contains(1, 2);47Component c1 = mb.add(new Component(){});48Component c2 = mb.add(new Component(){});49Component c3 = mb.add(new Component(){});50Insets ins = mb.getInsets();51mb.getAlignmentY();52mb.getAlignmentX();53mb.getGraphics();54mb.setVisible(false);55mb.setVisible(true);56mb.setForeground(Color.red);57mb.setBackground(Color.red);58for (String font : Toolkit.getDefaultToolkit().getFontList()) {59for (int j = 8; j < 17; j++) {60Font f1 = new Font(font, Font.PLAIN, j);61Font f2 = new Font(font, Font.BOLD, j);62Font f3 = new Font(font, Font.ITALIC, j);63Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);6465mb.setFont(f1);66mb.setFont(f2);67mb.setFont(f3);68mb.setFont(f4);6970mb.getFontMetrics(f1);71mb.getFontMetrics(f2);72mb.getFontMetrics(f3);73mb.getFontMetrics(f4);74}75}76mb.enable();77mb.disable();78mb.reshape(10, 10, 10, 10);79mb.getBounds(new Rectangle(1, 1, 1, 1));80mb.getSize(new Dimension(1, 2));81mb.getLocation(new Point(1, 2));82mb.getX();83mb.getY();84mb.getWidth();85mb.getHeight();86mb.isOpaque();87mb.isValidateRoot();88mb.isOptimizedDrawingEnabled();89mb.isDoubleBuffered();90mb.getComponentCount();91mb.countComponents();92mb.getComponent(1);93mb.getComponent(2);94Component[] cs = mb.getComponents();95mb.getLayout();96mb.setLayout(new FlowLayout());97mb.doLayout();98mb.layout();99mb.invalidate();100mb.validate();101mb.remove(0);102mb.remove(c2);103mb.removeAll();104mb.preferredSize();105mb.minimumSize();106mb.getComponentAt(1, 2);107mb.locate(1, 2);108mb.getComponentAt(new Point(1, 2));109mb.isFocusCycleRoot(new Container());110mb.transferFocusBackward();111mb.setName("goober");112mb.getName();113mb.getParent();114mb.getGraphicsConfiguration();115mb.getTreeLock();116mb.getToolkit();117mb.isValid();118mb.isDisplayable();119mb.isVisible();120mb.isShowing();121mb.isEnabled();122mb.enable(false);123mb.enable(true);124mb.enableInputMethods(false);125mb.enableInputMethods(true);126mb.show();127mb.show(false);128mb.show(true);129mb.hide();130mb.getForeground();131mb.isForegroundSet();132mb.getBackground();133mb.isBackgroundSet();134mb.getFont();135mb.isFontSet();136Container c = new Container();137c.add(mb);138mb.getLocale();139for (Locale locale : Locale.getAvailableLocales())140mb.setLocale(locale);141142mb.getColorModel();143mb.getLocation();144145boolean exceptions = false;146try {147mb.getLocationOnScreen();148} catch (IllegalComponentStateException e) {149exceptions = true;150}151if (!exceptions)152throw new RuntimeException("IllegalComponentStateException did not occur when expected");153154mb.location();155mb.setLocation(1, 2);156mb.move(1, 2);157mb.setLocation(new Point(1, 2));158mb.getSize();159mb.size();160mb.setSize(1, 32);161mb.resize(1, 32);162mb.setSize(new Dimension(1, 32));163mb.resize(new Dimension(1, 32));164mb.getBounds();165mb.bounds();166mb.setBounds(10, 10, 10, 10);167mb.setBounds(new Rectangle(10, 10, 10, 10));168mb.isLightweight();169mb.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));170mb.getCursor();171mb.isCursorSet();172mb.inside(1, 2);173mb.contains(new Point(1, 2));174mb.isFocusable();175mb.setFocusable(true);176mb.setFocusable(false);177mb.transferFocus();178mb.getFocusCycleRootAncestor();179mb.nextFocus();180mb.transferFocusUpCycle();181mb.hasFocus();182mb.isFocusOwner();183mb.toString();184mb.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);185mb.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);186mb.setComponentOrientation(ComponentOrientation.UNKNOWN);187mb.getComponentOrientation();188}189}190191192