Path: blob/master/test/jdk/javax/swing/Headless/HeadlessJPopupMenu.java
41149 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 JPopupMenu constructor and methods do not throw unexpected30* exceptions in headless mode31* @run main/othervm -Djava.awt.headless=true HeadlessJPopupMenu32*/3334public class HeadlessJPopupMenu {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.getGraphicsConfiguration();113m.getTreeLock();114m.getToolkit();115m.isValid();116m.isDisplayable();117m.isVisible();118m.isShowing();119m.isEnabled();120m.enable(false);121m.enable(true);122m.enableInputMethods(false);123m.enableInputMethods(true);124m.show();125m.show(false);126m.show(true);127m.hide();128m.getForeground();129m.isForegroundSet();130m.getBackground();131m.isBackgroundSet();132m.getFont();133m.isFontSet();134Container c = new Container();135c.add(m);136m.getLocale();137for (Locale locale : Locale.getAvailableLocales())138m.setLocale(locale);139140m.getColorModel();141m.getLocation();142143boolean exceptions = false;144try {145m.getLocationOnScreen();146} catch (IllegalComponentStateException e) {147exceptions = true;148}149if (!exceptions)150throw new RuntimeException("IllegalComponentStateException did not occur when expected");151152m.location();153m.setLocation(1, 2);154m.move(1, 2);155m.setLocation(new Point(1, 2));156m.getSize();157m.size();158m.setSize(1, 32);159m.resize(1, 32);160m.setSize(new Dimension(1, 32));161m.resize(new Dimension(1, 32));162m.getBounds();163m.bounds();164m.setBounds(10, 10, 10, 10);165m.setBounds(new Rectangle(10, 10, 10, 10));166m.isLightweight();167m.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));168m.getCursor();169m.isCursorSet();170m.inside(1, 2);171m.contains(new Point(1, 2));172m.isFocusable();173m.setFocusable(true);174m.setFocusable(false);175m.transferFocus();176m.getFocusCycleRootAncestor();177m.nextFocus();178m.transferFocusUpCycle();179m.hasFocus();180m.isFocusOwner();181m.toString();182m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);183m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);184m.setComponentOrientation(ComponentOrientation.UNKNOWN);185m.getComponentOrientation();186}187}188189190