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