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