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