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