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