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