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