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