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