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