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