Path: blob/master/test/jdk/javax/swing/Headless/HeadlessBox.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 Box constructors and methods do not throw30* unexpected exceptions in headless mode31* @run main/othervm -Djava.awt.headless=true HeadlessBox32*/3334public class HeadlessBox {3536public static void main(String args[]) {37for (Box b : new Box[]{new Box(BoxLayout.X_AXIS), new Box(BoxLayout.Y_AXIS)}) {38b = Box.createHorizontalBox();39b = Box.createVerticalBox();40b = new Box(BoxLayout.Y_AXIS);41b.getAccessibleContext();42b.requestFocus();43b.requestFocusInWindow();44b.getPreferredSize();45b.getMaximumSize();46b.getMinimumSize();47b.contains(1, 2);48Component c1 = b.add(new Component() {49});50Component c2 = b.add(new Component() {51});52Component c3 = b.add(new Component() {53});54b.getComponentCount();55b.countComponents();56b.getComponent(1);57b.getComponent(2);58Component[] cs = b.getComponents();5960boolean exceptions = false;61try {62b.setLayout(new BoxLayout(new Container(), BoxLayout.Y_AXIS));63} catch (AWTError e) {64exceptions = true;65}66if (!exceptions)67throw new RuntimeException("AWTError did not occur when expected");6869exceptions = false;70try {71b.setLayout(new BoxLayout(new Container(), BoxLayout.X_AXIS));72} catch (AWTError e) {73exceptions = true;74}75if (!exceptions)76throw new RuntimeException("AWTError did not occur when expected");7778b.getLayout();79b.invalidate();80b.validate();81b.revalidate();8283Insets ins = b.getInsets();84b.getAlignmentY();85b.getAlignmentX();86b.getGraphics();87b.setVisible(false);88b.setVisible(true);89b.setEnabled(false);90b.setEnabled(true);91b.setForeground(Color.red);92b.setBackground(Color.red);9394for (String font : Toolkit.getDefaultToolkit().getFontList()) {95for (int j = 8; j < 17; j++) {96Font f1 = new Font(font, Font.PLAIN, j);97Font f2 = new Font(font, Font.BOLD, j);98Font f3 = new Font(font, Font.ITALIC, j);99Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);100101b.setFont(f1);102b.setFont(f2);103b.setFont(f3);104b.setFont(f4);105106b.getFontMetrics(f1);107b.getFontMetrics(f2);108b.getFontMetrics(f3);109b.getFontMetrics(f4);110111}112}113114b.enable();115b.disable();116b.reshape(10, 10, 10, 10);117b.getBounds(new Rectangle(1, 1, 1, 1));118b.getSize(new Dimension(1, 2));119b.getSize(new Dimension(1, 2));120b.getLocation(new Point(1, 2));121b.getX();122b.getY();123b.getWidth();124b.getHeight();125b.isOpaque();126b.isValidateRoot();127b.isOptimizedDrawingEnabled();128b.isDoubleBuffered();129130b.remove(0);131b.remove(c2);132b.removeAll();133b.layout();134b.preferredSize();135b.minimumSize();136b.getComponentAt(1, 2);137b.locate(1, 2);138b.getComponentAt(new Point(1, 2));139b.isFocusCycleRoot(new Container());140b.transferFocusBackward();141b.setName("goober");142b.getName();143b.getParent();144b.getGraphicsConfiguration();145b.getTreeLock();146b.getToolkit();147b.isValid();148b.isDisplayable();149b.isVisible();150b.isShowing();151b.isEnabled();152b.enable(false);153b.enable(true);154b.enableInputMethods(false);155b.enableInputMethods(true);156b.show();157b.show(false);158b.show(true);159b.hide();160b.getForeground();161b.isForegroundSet();162b.getBackground();163b.isBackgroundSet();164b.getFont();165b.isFontSet();166b.getLocale();167for (Locale locale : Locale.getAvailableLocales())168b.setLocale(locale);169170b.getColorModel();171b.getLocation();172173exceptions = false;174try {175b.getLocationOnScreen();176} catch (IllegalComponentStateException e) {177exceptions = true;178}179if (!exceptions)180throw new RuntimeException("IllegalComponentStateException did not occur when expected");181182b.location();183b.setLocation(1, 2);184b.move(1, 2);185b.setLocation(new Point(1, 2));186b.getSize();187b.size();188b.setSize(1, 32);189b.resize(1, 32);190b.setSize(new Dimension(1, 32));191b.resize(new Dimension(1, 32));192b.getBounds();193b.bounds();194b.setBounds(10, 10, 10, 10);195b.setBounds(new Rectangle(10, 10, 10, 10));196b.isLightweight();197b.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));198b.getCursor();199b.isCursorSet();200b.inside(1, 2);201b.contains(new Point(1, 2));202b.isFocusTraversable();203b.isFocusable();204b.setFocusable(true);205b.setFocusable(false);206b.transferFocus();207b.getFocusCycleRootAncestor();208b.nextFocus();209b.transferFocusUpCycle();210b.hasFocus();211b.isFocusOwner();212b.toString();213b.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);214b.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);215b.setComponentOrientation(ComponentOrientation.UNKNOWN);216b.getComponentOrientation();217}218}219}220221222