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