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