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