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