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