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