1 /*
   2  * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import javax.swing.*;
  25 import java.awt.*;
  26 import java.util.Locale;
  27 
  28 /*
  29  * @test
  30  * @summary Check that JComboBox constructor and methods do not throw unexpected
  31  *          exceptions in headless mode
  32  * @run main/othervm -Djava.awt.headless=true HeadlessJComboBox
  33  */
  34 
  35 public class HeadlessJComboBox {
  36     public static void main(String args[]) {
  37         JComboBox ch;
  38         ch = new JComboBox();
  39         ch.getAccessibleContext();
  40         ch.isFocusTraversable();
  41         ch.setEnabled(false);
  42         ch.setEnabled(true);
  43         ch.requestFocus();
  44         ch.requestFocusInWindow();
  45         ch.getPreferredSize();
  46         ch.getMaximumSize();
  47         ch.getMinimumSize();
  48         ch.contains(1, 2);
  49         Component c1 = ch.add(new Component(){});
  50         Component c2 = ch.add(new Component(){});
  51         Component c3 = ch.add(new Component(){});
  52         Insets ins = ch.getInsets();
  53         ch.getAlignmentY();
  54         ch.getAlignmentX();
  55         ch.getGraphics();
  56         ch.setVisible(false);
  57         ch.setVisible(true);
  58         ch.setForeground(Color.red);
  59         ch.setBackground(Color.red);
  60         for (String font : Toolkit.getDefaultToolkit().getFontList()) {
  61             for (int j = 8; j < 17; j++) {
  62                 Font f1 = new Font(font, Font.PLAIN, j);
  63                 Font f2 = new Font(font, Font.BOLD, j);
  64                 Font f3 = new Font(font, Font.ITALIC, j);
  65                 Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);
  66 
  67                 ch.setFont(f1);
  68                 ch.setFont(f2);
  69                 ch.setFont(f3);
  70                 ch.setFont(f4);
  71 
  72                 ch.getFontMetrics(f1);
  73                 ch.getFontMetrics(f2);
  74                 ch.getFontMetrics(f3);
  75                 ch.getFontMetrics(f4);
  76             }
  77         }
  78         ch.enable();
  79         ch.disable();
  80         ch.reshape(10, 10, 10, 10);
  81         ch.getBounds(new Rectangle(1, 1, 1, 1));
  82         ch.getSize(new Dimension(1, 2));
  83         ch.getLocation(new Point(1, 2));
  84         ch.getX();
  85         ch.getY();
  86         ch.getWidth();
  87         ch.getHeight();
  88         ch.isOpaque();
  89         ch.isValidateRoot();
  90         ch.isOptimizedDrawingEnabled();
  91         ch.isDoubleBuffered();
  92         ch.getComponentCount();
  93         ch.countComponents();
  94         ch.getComponent(1);
  95         ch.getComponent(2);
  96         Component[] cs = ch.getComponents();
  97         ch.getLayout();
  98         ch.setLayout(new FlowLayout());
  99         ch.doLayout();
 100         ch.layout();
 101         ch.invalidate();
 102         ch.validate();
 103         ch.remove(0);
 104         ch.remove(c2);
 105         ch.removeAll();
 106         ch.preferredSize();
 107         ch.minimumSize();
 108         ch.getComponentAt(1, 2);
 109         ch.locate(1, 2);
 110         ch.getComponentAt(new Point(1, 2));
 111         ch.isFocusCycleRoot(new Container());
 112         ch.transferFocusBackward();
 113         ch.setName("goober");
 114         ch.getName();
 115         ch.getParent();
 116         ch.getPeer();
 117         ch.getGraphicsConfiguration();
 118         ch.getTreeLock();
 119         ch.getToolkit();
 120         ch.isValid();
 121         ch.isDisplayable();
 122         ch.isVisible();
 123         ch.isShowing();
 124         ch.isEnabled();
 125         ch.enable(false);
 126         ch.enable(true);
 127         ch.enableInputMethods(false);
 128         ch.enableInputMethods(true);
 129         ch.show();
 130         ch.show(false);
 131         ch.show(true);
 132         ch.hide();
 133         ch.getForeground();
 134         ch.isForegroundSet();
 135         ch.getBackground();
 136         ch.isBackgroundSet();
 137         ch.getFont();
 138         ch.isFontSet();
 139         Container c = new Container();
 140         c.add(ch);
 141         ch.getLocale();
 142         for (Locale locale : Locale.getAvailableLocales())
 143             ch.setLocale(locale);
 144 
 145         ch.getColorModel();
 146         ch.getLocation();
 147 
 148         boolean exceptions = false;
 149         try {
 150             ch.getLocationOnScreen();
 151         } catch (IllegalComponentStateException e) {
 152             exceptions = true;
 153         }
 154         if (!exceptions)
 155             throw new RuntimeException("IllegalComponentStateException did not occur when expected");
 156 
 157         ch.location();
 158         ch.setLocation(1, 2);
 159         ch.move(1, 2);
 160         ch.setLocation(new Point(1, 2));
 161         ch.getSize();
 162         ch.size();
 163         ch.setSize(1, 32);
 164         ch.resize(1, 32);
 165         ch.setSize(new Dimension(1, 32));
 166         ch.resize(new Dimension(1, 32));
 167         ch.getBounds();
 168         ch.bounds();
 169         ch.setBounds(10, 10, 10, 10);
 170         ch.setBounds(new Rectangle(10, 10, 10, 10));
 171         ch.isLightweight();
 172         ch.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
 173         ch.getCursor();
 174         ch.isCursorSet();
 175         ch.inside(1, 2);
 176         ch.contains(new Point(1, 2));
 177         ch.isFocusable();
 178         ch.setFocusable(true);
 179         ch.setFocusable(false);
 180         ch.transferFocus();
 181         ch.getFocusCycleRootAncestor();
 182         ch.nextFocus();
 183         ch.transferFocusUpCycle();
 184         ch.hasFocus();
 185         ch.isFocusOwner();
 186         ch.toString();
 187         ch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
 188         ch.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
 189         ch.setComponentOrientation(ComponentOrientation.UNKNOWN);
 190         ch.getComponentOrientation();
 191     }
 192 }