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