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