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