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