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