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