Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/Headless/HeadlessJMenuItem.java
38840 views
/*1* Copyright (c) 2007, 2014, 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.getPeer();115mi.getGraphicsConfiguration();116mi.getTreeLock();117mi.getToolkit();118mi.isValid();119mi.isDisplayable();120mi.isVisible();121mi.isShowing();122mi.isEnabled();123mi.enable(false);124mi.enable(true);125mi.enableInputMethods(false);126mi.enableInputMethods(true);127mi.show();128mi.show(false);129mi.show(true);130mi.hide();131mi.getForeground();132mi.isForegroundSet();133mi.getBackground();134mi.isBackgroundSet();135mi.getFont();136mi.isFontSet();137Container c = new Container();138c.add(mi);139mi.getLocale();140for (Locale locale : Locale.getAvailableLocales())141mi.setLocale(locale);142143mi.getColorModel();144mi.getLocation();145146boolean exceptions = false;147try {148mi.getLocationOnScreen();149} catch (IllegalComponentStateException e) {150exceptions = true;151}152if (!exceptions)153throw new RuntimeException("IllegalComponentStateException did not occur when expected");154155mi.location();156mi.setLocation(1, 2);157mi.move(1, 2);158mi.setLocation(new Point(1, 2));159mi.getSize();160mi.size();161mi.setSize(1, 32);162mi.resize(1, 32);163mi.setSize(new Dimension(1, 32));164mi.resize(new Dimension(1, 32));165mi.getBounds();166mi.bounds();167mi.setBounds(10, 10, 10, 10);168mi.setBounds(new Rectangle(10, 10, 10, 10));169mi.isLightweight();170mi.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));171mi.getCursor();172mi.isCursorSet();173mi.inside(1, 2);174mi.contains(new Point(1, 2));175mi.isFocusable();176mi.setFocusable(true);177mi.setFocusable(false);178mi.transferFocus();179mi.getFocusCycleRootAncestor();180mi.nextFocus();181mi.transferFocusUpCycle();182mi.hasFocus();183mi.isFocusOwner();184mi.toString();185mi.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);186mi.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);187mi.setComponentOrientation(ComponentOrientation.UNKNOWN);188mi.getComponentOrientation();189}190}191192193