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