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