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