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