author | malenkov |
Wed, 30 Apr 2014 19:28:05 +0400 | |
changeset 24544 | c0133e7c7162 |
parent 23715 | 54ae9dd9df73 |
child 25201 | 4adc75e0c4e5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
21982
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing; |
|
26 |
||
27 |
import java.awt.*; |
|
28 |
import java.awt.event.*; |
|
29 |
import java.beans.PropertyChangeListener; |
|
30 |
import java.util.Locale; |
|
31 |
import java.util.Vector; |
|
32 |
import java.io.Serializable; |
|
33 |
||
34 |
import javax.accessibility.*; |
|
35 |
||
36 |
||
37 |
/** |
|
38 |
* An extended version of <code>java.awt.Frame</code> that adds support for |
|
39 |
* the JFC/Swing component architecture. |
|
40 |
* You can find task-oriented documentation about using <code>JFrame</code> |
|
41 |
* in <em>The Java Tutorial</em>, in the section |
|
42 |
* <a |
|
20455
f6f9a0c2796b
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents:
15976
diff
changeset
|
43 |
href="http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html">How to Make Frames</a>. |
2 | 44 |
* |
45 |
* <p> |
|
46 |
* The <code>JFrame</code> class is slightly incompatible with <code>Frame</code>. |
|
47 |
* Like all other JFC/Swing top-level containers, |
|
48 |
* a <code>JFrame</code> contains a <code>JRootPane</code> as its only child. |
|
49 |
* The <b>content pane</b> provided by the root pane should, |
|
50 |
* as a rule, contain |
|
51 |
* all the non-menu components displayed by the <code>JFrame</code>. |
|
52 |
* This is different from the AWT <code>Frame</code> case. |
|
21255
0afb44cd0215
7165112: Incomprehensible garbage in doc for RootPaneContainer
malenkov
parents:
20458
diff
changeset
|
53 |
* As a convenience, the {@code add}, {@code remove}, and {@code setLayout} |
0afb44cd0215
7165112: Incomprehensible garbage in doc for RootPaneContainer
malenkov
parents:
20458
diff
changeset
|
54 |
* methods of this class are overridden, so that they delegate calls |
0afb44cd0215
7165112: Incomprehensible garbage in doc for RootPaneContainer
malenkov
parents:
20458
diff
changeset
|
55 |
* to the corresponding methods of the {@code ContentPane}. |
0afb44cd0215
7165112: Incomprehensible garbage in doc for RootPaneContainer
malenkov
parents:
20458
diff
changeset
|
56 |
* For example, you can add a child component to a frame as follows: |
2 | 57 |
* <pre> |
58 |
* frame.add(child); |
|
59 |
* </pre> |
|
60 |
* And the child will be added to the contentPane. |
|
61 |
* The content pane will |
|
62 |
* always be non-null. Attempting to set it to null will cause the JFrame |
|
63 |
* to throw an exception. The default content pane will have a BorderLayout |
|
64 |
* manager set on it. |
|
65 |
* Refer to {@link javax.swing.RootPaneContainer} |
|
66 |
* for details on adding, removing and setting the <code>LayoutManager</code> |
|
67 |
* of a <code>JFrame</code>. |
|
68 |
* <p> |
|
69 |
* Unlike a <code>Frame</code>, a <code>JFrame</code> has some notion of how to |
|
70 |
* respond when the user attempts to close the window. The default behavior |
|
71 |
* is to simply hide the JFrame when the user closes the window. To change the |
|
72 |
* default behavior, you invoke the method |
|
73 |
* {@link #setDefaultCloseOperation}. |
|
74 |
* To make the <code>JFrame</code> behave the same as a <code>Frame</code> |
|
75 |
* instance, use |
|
76 |
* <code>setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)</code>. |
|
77 |
* <p> |
|
78 |
* For more information on content panes |
|
79 |
* and other features that root panes provide, |
|
80 |
* see <a |
|
20455
f6f9a0c2796b
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents:
15976
diff
changeset
|
81 |
href="http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html">Using Top-Level Containers</a> in <em>The Java Tutorial</em>. |
2 | 82 |
* <p> |
83 |
* In a multi-screen environment, you can create a <code>JFrame</code> |
|
84 |
* on a different screen device. See {@link java.awt.Frame} for more |
|
85 |
* information. |
|
86 |
* <p> |
|
87 |
* <strong>Warning:</strong> Swing is not thread safe. For more |
|
88 |
* information see <a |
|
89 |
* href="package-summary.html#threading">Swing's Threading |
|
90 |
* Policy</a>. |
|
91 |
* <p> |
|
92 |
* <strong>Warning:</strong> |
|
93 |
* Serialized objects of this class will not be compatible with |
|
94 |
* future Swing releases. The current serialization support is |
|
95 |
* appropriate for short term storage or RMI between applications running |
|
96 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 97 |
* of all JavaBeans™ |
2 | 98 |
* has been added to the <code>java.beans</code> package. |
99 |
* Please see {@link java.beans.XMLEncoder}. |
|
100 |
* |
|
101 |
* @see JRootPane |
|
102 |
* @see #setDefaultCloseOperation |
|
103 |
* @see java.awt.event.WindowListener#windowClosing |
|
104 |
* @see javax.swing.RootPaneContainer |
|
105 |
* |
|
106 |
* @beaninfo |
|
107 |
* attribute: isContainer true |
|
108 |
* attribute: containerDelegate getContentPane |
|
109 |
* description: A toplevel window which can be minimized to an icon. |
|
110 |
* |
|
111 |
* @author Jeff Dinkins |
|
112 |
* @author Georges Saab |
|
113 |
* @author David Kloba |
|
114 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
21982
diff
changeset
|
115 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 116 |
public class JFrame extends Frame implements WindowConstants, |
117 |
Accessible, |
|
118 |
RootPaneContainer, |
|
119 |
TransferHandler.HasGetTransferHandler |
|
120 |
{ |
|
121 |
/** |
|
122 |
* The exit application default window close operation. If a window |
|
123 |
* has this set as the close operation and is closed in an applet, |
|
124 |
* a <code>SecurityException</code> may be thrown. |
|
125 |
* It is recommended you only use this in an application. |
|
23715 | 126 |
* |
2 | 127 |
* @since 1.3 |
128 |
*/ |
|
129 |
public static final int EXIT_ON_CLOSE = 3; |
|
130 |
||
131 |
/** |
|
132 |
* Key into the AppContext, used to check if should provide decorations |
|
133 |
* by default. |
|
134 |
*/ |
|
135 |
private static final Object defaultLookAndFeelDecoratedKey = |
|
136 |
new StringBuffer("JFrame.defaultLookAndFeelDecorated"); |
|
137 |
||
138 |
private int defaultCloseOperation = HIDE_ON_CLOSE; |
|
139 |
||
140 |
/** |
|
141 |
* The <code>TransferHandler</code> for this frame. |
|
142 |
*/ |
|
143 |
private TransferHandler transferHandler; |
|
144 |
||
145 |
/** |
|
146 |
* The <code>JRootPane</code> instance that manages the |
|
147 |
* <code>contentPane</code> |
|
148 |
* and optional <code>menuBar</code> for this frame, as well as the |
|
149 |
* <code>glassPane</code>. |
|
150 |
* |
|
151 |
* @see JRootPane |
|
152 |
* @see RootPaneContainer |
|
153 |
*/ |
|
154 |
protected JRootPane rootPane; |
|
155 |
||
156 |
/** |
|
157 |
* If true then calls to <code>add</code> and <code>setLayout</code> |
|
158 |
* will be forwarded to the <code>contentPane</code>. This is initially |
|
159 |
* false, but is set to true when the <code>JFrame</code> is constructed. |
|
160 |
* |
|
161 |
* @see #isRootPaneCheckingEnabled |
|
162 |
* @see #setRootPaneCheckingEnabled |
|
163 |
* @see javax.swing.RootPaneContainer |
|
164 |
*/ |
|
165 |
protected boolean rootPaneCheckingEnabled = false; |
|
166 |
||
167 |
||
168 |
/** |
|
169 |
* Constructs a new frame that is initially invisible. |
|
170 |
* <p> |
|
171 |
* This constructor sets the component's locale property to the value |
|
172 |
* returned by <code>JComponent.getDefaultLocale</code>. |
|
173 |
* |
|
174 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless() |
|
175 |
* returns true. |
|
176 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
177 |
* @see Component#setSize |
|
178 |
* @see Component#setVisible |
|
179 |
* @see JComponent#getDefaultLocale |
|
180 |
*/ |
|
181 |
public JFrame() throws HeadlessException { |
|
182 |
super(); |
|
183 |
frameInit(); |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* Creates a <code>Frame</code> in the specified |
|
188 |
* <code>GraphicsConfiguration</code> of |
|
189 |
* a screen device and a blank title. |
|
190 |
* <p> |
|
191 |
* This constructor sets the component's locale property to the value |
|
192 |
* returned by <code>JComponent.getDefaultLocale</code>. |
|
193 |
* |
|
194 |
* @param gc the <code>GraphicsConfiguration</code> that is used |
|
195 |
* to construct the new <code>Frame</code>; |
|
196 |
* if <code>gc</code> is <code>null</code>, the system |
|
197 |
* default <code>GraphicsConfiguration</code> is assumed |
|
198 |
* @exception IllegalArgumentException if <code>gc</code> is not from |
|
199 |
* a screen device. This exception is always thrown when |
|
200 |
* GraphicsEnvironment.isHeadless() returns true. |
|
201 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
202 |
* @see JComponent#getDefaultLocale |
|
203 |
* @since 1.3 |
|
204 |
*/ |
|
205 |
public JFrame(GraphicsConfiguration gc) { |
|
206 |
super(gc); |
|
207 |
frameInit(); |
|
208 |
} |
|
209 |
||
210 |
/** |
|
211 |
* Creates a new, initially invisible <code>Frame</code> with the |
|
212 |
* specified title. |
|
213 |
* <p> |
|
214 |
* This constructor sets the component's locale property to the value |
|
215 |
* returned by <code>JComponent.getDefaultLocale</code>. |
|
216 |
* |
|
217 |
* @param title the title for the frame |
|
218 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless() |
|
219 |
* returns true. |
|
220 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
221 |
* @see Component#setSize |
|
222 |
* @see Component#setVisible |
|
223 |
* @see JComponent#getDefaultLocale |
|
224 |
*/ |
|
225 |
public JFrame(String title) throws HeadlessException { |
|
226 |
super(title); |
|
227 |
frameInit(); |
|
228 |
} |
|
229 |
||
230 |
/** |
|
231 |
* Creates a <code>JFrame</code> with the specified title and the |
|
232 |
* specified <code>GraphicsConfiguration</code> of a screen device. |
|
233 |
* <p> |
|
234 |
* This constructor sets the component's locale property to the value |
|
235 |
* returned by <code>JComponent.getDefaultLocale</code>. |
|
236 |
* |
|
237 |
* @param title the title to be displayed in the |
|
238 |
* frame's border. A <code>null</code> value is treated as |
|
239 |
* an empty string, "". |
|
240 |
* @param gc the <code>GraphicsConfiguration</code> that is used |
|
241 |
* to construct the new <code>JFrame</code> with; |
|
242 |
* if <code>gc</code> is <code>null</code>, the system |
|
243 |
* default <code>GraphicsConfiguration</code> is assumed |
|
244 |
* @exception IllegalArgumentException if <code>gc</code> is not from |
|
245 |
* a screen device. This exception is always thrown when |
|
246 |
* GraphicsEnvironment.isHeadless() returns true. |
|
247 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
248 |
* @see JComponent#getDefaultLocale |
|
249 |
* @since 1.3 |
|
250 |
*/ |
|
251 |
public JFrame(String title, GraphicsConfiguration gc) { |
|
252 |
super(title, gc); |
|
253 |
frameInit(); |
|
254 |
} |
|
255 |
||
256 |
/** Called by the constructors to init the <code>JFrame</code> properly. */ |
|
257 |
protected void frameInit() { |
|
258 |
enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK); |
|
259 |
setLocale( JComponent.getDefaultLocale() ); |
|
260 |
setRootPane(createRootPane()); |
|
261 |
setBackground(UIManager.getColor("control")); |
|
262 |
setRootPaneCheckingEnabled(true); |
|
263 |
if (JFrame.isDefaultLookAndFeelDecorated()) { |
|
264 |
boolean supportsWindowDecorations = |
|
265 |
UIManager.getLookAndFeel().getSupportsWindowDecorations(); |
|
266 |
if (supportsWindowDecorations) { |
|
267 |
setUndecorated(true); |
|
268 |
getRootPane().setWindowDecorationStyle(JRootPane.FRAME); |
|
269 |
} |
|
270 |
} |
|
12661
6cf8b7116579
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents:
5506
diff
changeset
|
271 |
sun.awt.SunToolkit.checkAndSetPolicy(this); |
2 | 272 |
} |
273 |
||
274 |
/** |
|
275 |
* Called by the constructor methods to create the default |
|
276 |
* <code>rootPane</code>. |
|
277 |
*/ |
|
278 |
protected JRootPane createRootPane() { |
|
279 |
JRootPane rp = new JRootPane(); |
|
280 |
// NOTE: this uses setOpaque vs LookAndFeel.installProperty as there |
|
281 |
// is NO reason for the RootPane not to be opaque. For painting to |
|
282 |
// work the contentPane must be opaque, therefor the RootPane can |
|
283 |
// also be opaque. |
|
284 |
rp.setOpaque(true); |
|
285 |
return rp; |
|
286 |
} |
|
287 |
||
288 |
/** |
|
289 |
* Processes window events occurring on this component. |
|
290 |
* Hides the window or disposes of it, as specified by the setting |
|
291 |
* of the <code>defaultCloseOperation</code> property. |
|
292 |
* |
|
293 |
* @param e the window event |
|
294 |
* @see #setDefaultCloseOperation |
|
295 |
* @see java.awt.Window#processWindowEvent |
|
296 |
*/ |
|
297 |
protected void processWindowEvent(WindowEvent e) { |
|
298 |
super.processWindowEvent(e); |
|
299 |
||
300 |
if (e.getID() == WindowEvent.WINDOW_CLOSING) { |
|
301 |
switch(defaultCloseOperation) { |
|
302 |
case HIDE_ON_CLOSE: |
|
303 |
setVisible(false); |
|
304 |
break; |
|
305 |
case DISPOSE_ON_CLOSE: |
|
306 |
dispose(); |
|
307 |
break; |
|
308 |
case DO_NOTHING_ON_CLOSE: |
|
309 |
default: |
|
310 |
break; |
|
311 |
case EXIT_ON_CLOSE: |
|
312 |
// This needs to match the checkExit call in |
|
313 |
// setDefaultCloseOperation |
|
314 |
System.exit(0); |
|
315 |
break; |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
||
320 |
// public void setMenuBar(MenuBar menu) { |
|
321 |
// throw new IllegalComponentStateException("Please use setJMenuBar() with JFrame."); |
|
322 |
// } |
|
323 |
||
324 |
/** |
|
325 |
* Sets the operation that will happen by default when |
|
326 |
* the user initiates a "close" on this frame. |
|
327 |
* You must specify one of the following choices: |
|
21982 | 328 |
* <br><br> |
2 | 329 |
* <ul> |
330 |
* <li><code>DO_NOTHING_ON_CLOSE</code> |
|
331 |
* (defined in <code>WindowConstants</code>): |
|
332 |
* Don't do anything; require the |
|
333 |
* program to handle the operation in the <code>windowClosing</code> |
|
334 |
* method of a registered <code>WindowListener</code> object. |
|
335 |
* |
|
336 |
* <li><code>HIDE_ON_CLOSE</code> |
|
337 |
* (defined in <code>WindowConstants</code>): |
|
338 |
* Automatically hide the frame after |
|
339 |
* invoking any registered <code>WindowListener</code> |
|
340 |
* objects. |
|
341 |
* |
|
342 |
* <li><code>DISPOSE_ON_CLOSE</code> |
|
343 |
* (defined in <code>WindowConstants</code>): |
|
344 |
* Automatically hide and dispose the |
|
345 |
* frame after invoking any registered <code>WindowListener</code> |
|
346 |
* objects. |
|
347 |
* |
|
348 |
* <li><code>EXIT_ON_CLOSE</code> |
|
349 |
* (defined in <code>JFrame</code>): |
|
350 |
* Exit the application using the <code>System</code> |
|
351 |
* <code>exit</code> method. Use this only in applications. |
|
352 |
* </ul> |
|
353 |
* <p> |
|
354 |
* The value is set to <code>HIDE_ON_CLOSE</code> by default. Changes |
|
355 |
* to the value of this property cause the firing of a property |
|
356 |
* change event, with property name "defaultCloseOperation". |
|
357 |
* <p> |
|
358 |
* <b>Note</b>: When the last displayable window within the |
|
359 |
* Java virtual machine (VM) is disposed of, the VM may |
|
360 |
* terminate. See <a href="../../java/awt/doc-files/AWTThreadIssues.html"> |
|
361 |
* AWT Threading Issues</a> for more information. |
|
362 |
* |
|
363 |
* @param operation the operation which should be performed when the |
|
364 |
* user closes the frame |
|
365 |
* @exception IllegalArgumentException if defaultCloseOperation value |
|
366 |
* isn't one of the above valid values |
|
367 |
* @see #addWindowListener |
|
368 |
* @see #getDefaultCloseOperation |
|
369 |
* @see WindowConstants |
|
370 |
* @throws SecurityException |
|
371 |
* if <code>EXIT_ON_CLOSE</code> has been specified and the |
|
372 |
* <code>SecurityManager</code> will |
|
373 |
* not allow the caller to invoke <code>System.exit</code> |
|
374 |
* @see java.lang.Runtime#exit(int) |
|
375 |
* |
|
376 |
* @beaninfo |
|
377 |
* preferred: true |
|
378 |
* bound: true |
|
379 |
* enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE |
|
380 |
* HIDE_ON_CLOSE WindowConstants.HIDE_ON_CLOSE |
|
381 |
* DISPOSE_ON_CLOSE WindowConstants.DISPOSE_ON_CLOSE |
|
382 |
* EXIT_ON_CLOSE WindowConstants.EXIT_ON_CLOSE |
|
383 |
* description: The frame's default close operation. |
|
384 |
*/ |
|
385 |
public void setDefaultCloseOperation(int operation) { |
|
386 |
if (operation != DO_NOTHING_ON_CLOSE && |
|
387 |
operation != HIDE_ON_CLOSE && |
|
388 |
operation != DISPOSE_ON_CLOSE && |
|
389 |
operation != EXIT_ON_CLOSE) { |
|
390 |
throw new IllegalArgumentException("defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or EXIT_ON_CLOSE"); |
|
391 |
} |
|
15976
f9578ba3a2c1
7173873: JFrame.setDefaultCloseOperation(EXIT_ON_CLOSE) will never lead to SE if EXIT_ON_CLOSE is already set
alexsch
parents:
12661
diff
changeset
|
392 |
|
f9578ba3a2c1
7173873: JFrame.setDefaultCloseOperation(EXIT_ON_CLOSE) will never lead to SE if EXIT_ON_CLOSE is already set
alexsch
parents:
12661
diff
changeset
|
393 |
if (operation == EXIT_ON_CLOSE) { |
f9578ba3a2c1
7173873: JFrame.setDefaultCloseOperation(EXIT_ON_CLOSE) will never lead to SE if EXIT_ON_CLOSE is already set
alexsch
parents:
12661
diff
changeset
|
394 |
SecurityManager security = System.getSecurityManager(); |
f9578ba3a2c1
7173873: JFrame.setDefaultCloseOperation(EXIT_ON_CLOSE) will never lead to SE if EXIT_ON_CLOSE is already set
alexsch
parents:
12661
diff
changeset
|
395 |
if (security != null) { |
f9578ba3a2c1
7173873: JFrame.setDefaultCloseOperation(EXIT_ON_CLOSE) will never lead to SE if EXIT_ON_CLOSE is already set
alexsch
parents:
12661
diff
changeset
|
396 |
security.checkExit(0); |
f9578ba3a2c1
7173873: JFrame.setDefaultCloseOperation(EXIT_ON_CLOSE) will never lead to SE if EXIT_ON_CLOSE is already set
alexsch
parents:
12661
diff
changeset
|
397 |
} |
f9578ba3a2c1
7173873: JFrame.setDefaultCloseOperation(EXIT_ON_CLOSE) will never lead to SE if EXIT_ON_CLOSE is already set
alexsch
parents:
12661
diff
changeset
|
398 |
} |
2 | 399 |
if (this.defaultCloseOperation != operation) { |
400 |
int oldValue = this.defaultCloseOperation; |
|
401 |
this.defaultCloseOperation = operation; |
|
402 |
firePropertyChange("defaultCloseOperation", oldValue, operation); |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
||
407 |
/** |
|
408 |
* Returns the operation that occurs when the user |
|
409 |
* initiates a "close" on this frame. |
|
410 |
* |
|
411 |
* @return an integer indicating the window-close operation |
|
412 |
* @see #setDefaultCloseOperation |
|
413 |
*/ |
|
414 |
public int getDefaultCloseOperation() { |
|
415 |
return defaultCloseOperation; |
|
416 |
} |
|
417 |
||
418 |
/** |
|
419 |
* Sets the {@code transferHandler} property, which is a mechanism to |
|
420 |
* support transfer of data into this component. Use {@code null} |
|
421 |
* if the component does not support data transfer operations. |
|
422 |
* <p> |
|
423 |
* If the system property {@code suppressSwingDropSupport} is {@code false} |
|
424 |
* (the default) and the current drop target on this component is either |
|
425 |
* {@code null} or not a user-set drop target, this method will change the |
|
426 |
* drop target as follows: If {@code newHandler} is {@code null} it will |
|
427 |
* clear the drop target. If not {@code null} it will install a new |
|
428 |
* {@code DropTarget}. |
|
429 |
* <p> |
|
430 |
* Note: When used with {@code JFrame}, {@code TransferHandler} only |
|
431 |
* provides data import capability, as the data export related methods |
|
432 |
* are currently typed to {@code JComponent}. |
|
433 |
* <p> |
|
434 |
* Please see |
|
20455
f6f9a0c2796b
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents:
15976
diff
changeset
|
435 |
* <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html"> |
2 | 436 |
* How to Use Drag and Drop and Data Transfer</a>, a section in |
437 |
* <em>The Java Tutorial</em>, for more information. |
|
438 |
* |
|
439 |
* @param newHandler the new {@code TransferHandler} |
|
440 |
* |
|
441 |
* @see TransferHandler |
|
442 |
* @see #getTransferHandler |
|
443 |
* @see java.awt.Component#setDropTarget |
|
444 |
* @since 1.6 |
|
445 |
* |
|
446 |
* @beaninfo |
|
447 |
* bound: true |
|
448 |
* hidden: true |
|
449 |
* description: Mechanism for transfer of data into the component |
|
450 |
*/ |
|
451 |
public void setTransferHandler(TransferHandler newHandler) { |
|
452 |
TransferHandler oldHandler = transferHandler; |
|
453 |
transferHandler = newHandler; |
|
454 |
SwingUtilities.installSwingDropTargetAsNecessary(this, transferHandler); |
|
455 |
firePropertyChange("transferHandler", oldHandler, newHandler); |
|
456 |
} |
|
457 |
||
458 |
/** |
|
459 |
* Gets the <code>transferHandler</code> property. |
|
460 |
* |
|
461 |
* @return the value of the <code>transferHandler</code> property |
|
462 |
* |
|
463 |
* @see TransferHandler |
|
464 |
* @see #setTransferHandler |
|
465 |
* @since 1.6 |
|
466 |
*/ |
|
467 |
public TransferHandler getTransferHandler() { |
|
468 |
return transferHandler; |
|
469 |
} |
|
470 |
||
471 |
/** |
|
472 |
* Just calls <code>paint(g)</code>. This method was overridden to |
|
473 |
* prevent an unnecessary call to clear the background. |
|
474 |
* |
|
475 |
* @param g the Graphics context in which to paint |
|
476 |
*/ |
|
477 |
public void update(Graphics g) { |
|
478 |
paint(g); |
|
479 |
} |
|
480 |
||
481 |
/** |
|
482 |
* Sets the menubar for this frame. |
|
483 |
* @param menubar the menubar being placed in the frame |
|
484 |
* |
|
485 |
* @see #getJMenuBar |
|
486 |
* |
|
487 |
* @beaninfo |
|
488 |
* hidden: true |
|
489 |
* description: The menubar for accessing pulldown menus from this frame. |
|
490 |
*/ |
|
491 |
public void setJMenuBar(JMenuBar menubar) { |
|
492 |
getRootPane().setMenuBar(menubar); |
|
493 |
} |
|
494 |
||
495 |
/** |
|
496 |
* Returns the menubar set on this frame. |
|
497 |
* @return the menubar for this frame |
|
498 |
* |
|
499 |
* @see #setJMenuBar |
|
500 |
*/ |
|
501 |
public JMenuBar getJMenuBar() { |
|
502 |
return getRootPane().getMenuBar(); |
|
503 |
} |
|
504 |
||
505 |
/** |
|
506 |
* Returns whether calls to <code>add</code> and |
|
507 |
* <code>setLayout</code> are forwarded to the <code>contentPane</code>. |
|
508 |
* |
|
509 |
* @return true if <code>add</code> and <code>setLayout</code> |
|
21278 | 510 |
* are forwarded; false otherwise |
2 | 511 |
* |
512 |
* @see #addImpl |
|
513 |
* @see #setLayout |
|
514 |
* @see #setRootPaneCheckingEnabled |
|
515 |
* @see javax.swing.RootPaneContainer |
|
516 |
*/ |
|
517 |
protected boolean isRootPaneCheckingEnabled() { |
|
518 |
return rootPaneCheckingEnabled; |
|
519 |
} |
|
520 |
||
521 |
||
522 |
/** |
|
523 |
* Sets whether calls to <code>add</code> and |
|
524 |
* <code>setLayout</code> are forwarded to the <code>contentPane</code>. |
|
525 |
* |
|
526 |
* @param enabled true if <code>add</code> and <code>setLayout</code> |
|
527 |
* are forwarded, false if they should operate directly on the |
|
528 |
* <code>JFrame</code>. |
|
529 |
* |
|
530 |
* @see #addImpl |
|
531 |
* @see #setLayout |
|
532 |
* @see #isRootPaneCheckingEnabled |
|
533 |
* @see javax.swing.RootPaneContainer |
|
534 |
* @beaninfo |
|
535 |
* hidden: true |
|
536 |
* description: Whether the add and setLayout methods are forwarded |
|
537 |
*/ |
|
538 |
protected void setRootPaneCheckingEnabled(boolean enabled) { |
|
539 |
rootPaneCheckingEnabled = enabled; |
|
540 |
} |
|
541 |
||
542 |
||
543 |
/** |
|
544 |
* Adds the specified child <code>Component</code>. |
|
545 |
* This method is overridden to conditionally forward calls to the |
|
546 |
* <code>contentPane</code>. |
|
547 |
* By default, children are added to the <code>contentPane</code> instead |
|
548 |
* of the frame, refer to {@link javax.swing.RootPaneContainer} for |
|
549 |
* details. |
|
550 |
* |
|
551 |
* @param comp the component to be enhanced |
|
552 |
* @param constraints the constraints to be respected |
|
553 |
* @param index the index |
|
554 |
* @exception IllegalArgumentException if <code>index</code> is invalid |
|
555 |
* @exception IllegalArgumentException if adding the container's parent |
|
556 |
* to itself |
|
557 |
* @exception IllegalArgumentException if adding a window to a container |
|
558 |
* |
|
559 |
* @see #setRootPaneCheckingEnabled |
|
560 |
* @see javax.swing.RootPaneContainer |
|
561 |
*/ |
|
562 |
protected void addImpl(Component comp, Object constraints, int index) |
|
563 |
{ |
|
564 |
if(isRootPaneCheckingEnabled()) { |
|
565 |
getContentPane().add(comp, constraints, index); |
|
566 |
} |
|
567 |
else { |
|
568 |
super.addImpl(comp, constraints, index); |
|
569 |
} |
|
570 |
} |
|
571 |
||
572 |
/** |
|
573 |
* Removes the specified component from the container. If |
|
574 |
* <code>comp</code> is not the <code>rootPane</code>, this will forward |
|
575 |
* the call to the <code>contentPane</code>. This will do nothing if |
|
576 |
* <code>comp</code> is not a child of the <code>JFrame</code> or |
|
577 |
* <code>contentPane</code>. |
|
578 |
* |
|
579 |
* @param comp the component to be removed |
|
580 |
* @throws NullPointerException if <code>comp</code> is null |
|
581 |
* @see #add |
|
582 |
* @see javax.swing.RootPaneContainer |
|
583 |
*/ |
|
584 |
public void remove(Component comp) { |
|
585 |
if (comp == rootPane) { |
|
586 |
super.remove(comp); |
|
587 |
} else { |
|
588 |
getContentPane().remove(comp); |
|
589 |
} |
|
590 |
} |
|
591 |
||
592 |
||
593 |
/** |
|
594 |
* Sets the <code>LayoutManager</code>. |
|
595 |
* Overridden to conditionally forward the call to the |
|
596 |
* <code>contentPane</code>. |
|
597 |
* Refer to {@link javax.swing.RootPaneContainer} for |
|
598 |
* more information. |
|
599 |
* |
|
600 |
* @param manager the <code>LayoutManager</code> |
|
601 |
* @see #setRootPaneCheckingEnabled |
|
602 |
* @see javax.swing.RootPaneContainer |
|
603 |
*/ |
|
604 |
public void setLayout(LayoutManager manager) { |
|
605 |
if(isRootPaneCheckingEnabled()) { |
|
606 |
getContentPane().setLayout(manager); |
|
607 |
} |
|
608 |
else { |
|
609 |
super.setLayout(manager); |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
||
614 |
/** |
|
615 |
* Returns the <code>rootPane</code> object for this frame. |
|
616 |
* @return the <code>rootPane</code> property |
|
617 |
* |
|
618 |
* @see #setRootPane |
|
619 |
* @see RootPaneContainer#getRootPane |
|
620 |
*/ |
|
621 |
public JRootPane getRootPane() { |
|
622 |
return rootPane; |
|
623 |
} |
|
624 |
||
625 |
||
626 |
/** |
|
627 |
* Sets the <code>rootPane</code> property. |
|
628 |
* This method is called by the constructor. |
|
629 |
* @param root the <code>rootPane</code> object for this frame |
|
630 |
* |
|
631 |
* @see #getRootPane |
|
632 |
* |
|
633 |
* @beaninfo |
|
634 |
* hidden: true |
|
635 |
* description: the RootPane object for this frame. |
|
636 |
*/ |
|
637 |
protected void setRootPane(JRootPane root) |
|
638 |
{ |
|
639 |
if(rootPane != null) { |
|
640 |
remove(rootPane); |
|
641 |
} |
|
642 |
rootPane = root; |
|
643 |
if(rootPane != null) { |
|
644 |
boolean checkingEnabled = isRootPaneCheckingEnabled(); |
|
645 |
try { |
|
646 |
setRootPaneCheckingEnabled(false); |
|
647 |
add(rootPane, BorderLayout.CENTER); |
|
648 |
} |
|
649 |
finally { |
|
650 |
setRootPaneCheckingEnabled(checkingEnabled); |
|
651 |
} |
|
652 |
} |
|
653 |
} |
|
654 |
||
655 |
/** |
|
656 |
* {@inheritDoc} |
|
657 |
*/ |
|
658 |
public void setIconImage(Image image) { |
|
659 |
super.setIconImage(image); |
|
660 |
} |
|
661 |
||
662 |
/** |
|
663 |
* Returns the <code>contentPane</code> object for this frame. |
|
664 |
* @return the <code>contentPane</code> property |
|
665 |
* |
|
666 |
* @see #setContentPane |
|
667 |
* @see RootPaneContainer#getContentPane |
|
668 |
*/ |
|
669 |
public Container getContentPane() { |
|
670 |
return getRootPane().getContentPane(); |
|
671 |
} |
|
672 |
||
673 |
/** |
|
674 |
* Sets the <code>contentPane</code> property. |
|
675 |
* This method is called by the constructor. |
|
676 |
* <p> |
|
677 |
* Swing's painting architecture requires an opaque <code>JComponent</code> |
|
21278 | 678 |
* in the containment hierarchy. This is typically provided by the |
2 | 679 |
* content pane. If you replace the content pane it is recommended you |
680 |
* replace it with an opaque <code>JComponent</code>. |
|
681 |
* |
|
682 |
* @param contentPane the <code>contentPane</code> object for this frame |
|
683 |
* |
|
684 |
* @exception java.awt.IllegalComponentStateException (a runtime |
|
685 |
* exception) if the content pane parameter is <code>null</code> |
|
686 |
* @see #getContentPane |
|
687 |
* @see RootPaneContainer#setContentPane |
|
688 |
* @see JRootPane |
|
689 |
* |
|
690 |
* @beaninfo |
|
691 |
* hidden: true |
|
692 |
* description: The client area of the frame where child |
|
693 |
* components are normally inserted. |
|
694 |
*/ |
|
695 |
public void setContentPane(Container contentPane) { |
|
696 |
getRootPane().setContentPane(contentPane); |
|
697 |
} |
|
698 |
||
699 |
/** |
|
700 |
* Returns the <code>layeredPane</code> object for this frame. |
|
701 |
* @return the <code>layeredPane</code> property |
|
702 |
* |
|
703 |
* @see #setLayeredPane |
|
704 |
* @see RootPaneContainer#getLayeredPane |
|
705 |
*/ |
|
706 |
public JLayeredPane getLayeredPane() { |
|
707 |
return getRootPane().getLayeredPane(); |
|
708 |
} |
|
709 |
||
710 |
/** |
|
711 |
* Sets the <code>layeredPane</code> property. |
|
712 |
* This method is called by the constructor. |
|
713 |
* @param layeredPane the <code>layeredPane</code> object for this frame |
|
714 |
* |
|
715 |
* @exception java.awt.IllegalComponentStateException (a runtime |
|
716 |
* exception) if the layered pane parameter is <code>null</code> |
|
717 |
* @see #getLayeredPane |
|
718 |
* @see RootPaneContainer#setLayeredPane |
|
719 |
* |
|
720 |
* @beaninfo |
|
721 |
* hidden: true |
|
722 |
* description: The pane that holds the various frame layers. |
|
723 |
*/ |
|
724 |
public void setLayeredPane(JLayeredPane layeredPane) { |
|
725 |
getRootPane().setLayeredPane(layeredPane); |
|
726 |
} |
|
727 |
||
728 |
/** |
|
729 |
* Returns the <code>glassPane</code> object for this frame. |
|
730 |
* @return the <code>glassPane</code> property |
|
731 |
* |
|
732 |
* @see #setGlassPane |
|
733 |
* @see RootPaneContainer#getGlassPane |
|
734 |
*/ |
|
735 |
public Component getGlassPane() { |
|
736 |
return getRootPane().getGlassPane(); |
|
737 |
} |
|
738 |
||
739 |
/** |
|
740 |
* Sets the <code>glassPane</code> property. |
|
741 |
* This method is called by the constructor. |
|
742 |
* @param glassPane the <code>glassPane</code> object for this frame |
|
743 |
* |
|
744 |
* @see #getGlassPane |
|
745 |
* @see RootPaneContainer#setGlassPane |
|
746 |
* |
|
747 |
* @beaninfo |
|
748 |
* hidden: true |
|
749 |
* description: A transparent pane used for menu rendering. |
|
750 |
*/ |
|
751 |
public void setGlassPane(Component glassPane) { |
|
752 |
getRootPane().setGlassPane(glassPane); |
|
753 |
} |
|
754 |
||
755 |
/** |
|
756 |
* {@inheritDoc} |
|
757 |
* |
|
758 |
* @since 1.6 |
|
759 |
*/ |
|
760 |
public Graphics getGraphics() { |
|
761 |
JComponent.getGraphicsInvoked(this); |
|
762 |
return super.getGraphics(); |
|
763 |
} |
|
764 |
||
765 |
/** |
|
766 |
* Repaints the specified rectangle of this component within |
|
767 |
* <code>time</code> milliseconds. Refer to <code>RepaintManager</code> |
|
768 |
* for details on how the repaint is handled. |
|
769 |
* |
|
770 |
* @param time maximum time in milliseconds before update |
|
771 |
* @param x the <i>x</i> coordinate |
|
772 |
* @param y the <i>y</i> coordinate |
|
773 |
* @param width the width |
|
774 |
* @param height the height |
|
775 |
* @see RepaintManager |
|
776 |
* @since 1.6 |
|
777 |
*/ |
|
778 |
public void repaint(long time, int x, int y, int width, int height) { |
|
779 |
if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) { |
|
780 |
RepaintManager.currentManager(this).addDirtyRegion( |
|
781 |
this, x, y, width, height); |
|
782 |
} |
|
783 |
else { |
|
784 |
super.repaint(time, x, y, width, height); |
|
785 |
} |
|
786 |
} |
|
787 |
||
788 |
/** |
|
789 |
* Provides a hint as to whether or not newly created <code>JFrame</code>s |
|
790 |
* should have their Window decorations (such as borders, widgets to |
|
791 |
* close the window, title...) provided by the current look |
|
792 |
* and feel. If <code>defaultLookAndFeelDecorated</code> is true, |
|
793 |
* the current <code>LookAndFeel</code> supports providing window |
|
794 |
* decorations, and the current window manager supports undecorated |
|
795 |
* windows, then newly created <code>JFrame</code>s will have their |
|
796 |
* Window decorations provided by the current <code>LookAndFeel</code>. |
|
797 |
* Otherwise, newly created <code>JFrame</code>s will have their |
|
798 |
* Window decorations provided by the current window manager. |
|
799 |
* <p> |
|
800 |
* You can get the same effect on a single JFrame by doing the following: |
|
801 |
* <pre> |
|
802 |
* JFrame frame = new JFrame(); |
|
803 |
* frame.setUndecorated(true); |
|
804 |
* frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); |
|
805 |
* </pre> |
|
806 |
* |
|
807 |
* @param defaultLookAndFeelDecorated A hint as to whether or not current |
|
808 |
* look and feel should provide window decorations |
|
809 |
* @see javax.swing.LookAndFeel#getSupportsWindowDecorations |
|
810 |
* @since 1.4 |
|
811 |
*/ |
|
812 |
public static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated) { |
|
813 |
if (defaultLookAndFeelDecorated) { |
|
814 |
SwingUtilities.appContextPut(defaultLookAndFeelDecoratedKey, Boolean.TRUE); |
|
815 |
} else { |
|
816 |
SwingUtilities.appContextPut(defaultLookAndFeelDecoratedKey, Boolean.FALSE); |
|
817 |
} |
|
818 |
} |
|
819 |
||
820 |
||
821 |
/** |
|
822 |
* Returns true if newly created <code>JFrame</code>s should have their |
|
823 |
* Window decorations provided by the current look and feel. This is only |
|
824 |
* a hint, as certain look and feels may not support this feature. |
|
825 |
* |
|
826 |
* @return true if look and feel should provide Window decorations. |
|
827 |
* @since 1.4 |
|
828 |
*/ |
|
829 |
public static boolean isDefaultLookAndFeelDecorated() { |
|
830 |
Boolean defaultLookAndFeelDecorated = |
|
831 |
(Boolean) SwingUtilities.appContextGet(defaultLookAndFeelDecoratedKey); |
|
832 |
if (defaultLookAndFeelDecorated == null) { |
|
833 |
defaultLookAndFeelDecorated = Boolean.FALSE; |
|
834 |
} |
|
835 |
return defaultLookAndFeelDecorated.booleanValue(); |
|
836 |
} |
|
837 |
||
838 |
/** |
|
839 |
* Returns a string representation of this <code>JFrame</code>. |
|
840 |
* This method |
|
841 |
* is intended to be used only for debugging purposes, and the |
|
842 |
* content and format of the returned string may vary between |
|
843 |
* implementations. The returned string may be empty but may not |
|
844 |
* be <code>null</code>. |
|
845 |
* |
|
846 |
* @return a string representation of this <code>JFrame</code> |
|
847 |
*/ |
|
848 |
protected String paramString() { |
|
849 |
String defaultCloseOperationString; |
|
850 |
if (defaultCloseOperation == HIDE_ON_CLOSE) { |
|
851 |
defaultCloseOperationString = "HIDE_ON_CLOSE"; |
|
852 |
} else if (defaultCloseOperation == DISPOSE_ON_CLOSE) { |
|
853 |
defaultCloseOperationString = "DISPOSE_ON_CLOSE"; |
|
854 |
} else if (defaultCloseOperation == DO_NOTHING_ON_CLOSE) { |
|
855 |
defaultCloseOperationString = "DO_NOTHING_ON_CLOSE"; |
|
856 |
} else if (defaultCloseOperation == 3) { |
|
857 |
defaultCloseOperationString = "EXIT_ON_CLOSE"; |
|
858 |
} else defaultCloseOperationString = ""; |
|
859 |
String rootPaneString = (rootPane != null ? |
|
860 |
rootPane.toString() : ""); |
|
861 |
String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ? |
|
862 |
"true" : "false"); |
|
863 |
||
864 |
return super.paramString() + |
|
865 |
",defaultCloseOperation=" + defaultCloseOperationString + |
|
866 |
",rootPane=" + rootPaneString + |
|
867 |
",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString; |
|
868 |
} |
|
869 |
||
870 |
||
871 |
||
872 |
///////////////// |
|
873 |
// Accessibility support |
|
874 |
//////////////// |
|
875 |
||
876 |
/** The accessible context property. */ |
|
877 |
protected AccessibleContext accessibleContext = null; |
|
878 |
||
879 |
/** |
|
880 |
* Gets the AccessibleContext associated with this JFrame. |
|
881 |
* For JFrames, the AccessibleContext takes the form of an |
|
882 |
* AccessibleJFrame. |
|
883 |
* A new AccessibleJFrame instance is created if necessary. |
|
884 |
* |
|
885 |
* @return an AccessibleJFrame that serves as the |
|
886 |
* AccessibleContext of this JFrame |
|
887 |
*/ |
|
888 |
public AccessibleContext getAccessibleContext() { |
|
889 |
if (accessibleContext == null) { |
|
890 |
accessibleContext = new AccessibleJFrame(); |
|
891 |
} |
|
892 |
return accessibleContext; |
|
893 |
} |
|
894 |
||
895 |
/** |
|
896 |
* This class implements accessibility support for the |
|
897 |
* <code>JFrame</code> class. It provides an implementation of the |
|
898 |
* Java Accessibility API appropriate to frame user-interface |
|
899 |
* elements. |
|
900 |
*/ |
|
901 |
protected class AccessibleJFrame extends AccessibleAWTFrame { |
|
902 |
||
903 |
// AccessibleContext methods |
|
904 |
/** |
|
905 |
* Get the accessible name of this object. |
|
906 |
* |
|
907 |
* @return the localized name of the object -- can be null if this |
|
908 |
* object does not have a name |
|
909 |
*/ |
|
910 |
public String getAccessibleName() { |
|
911 |
if (accessibleName != null) { |
|
912 |
return accessibleName; |
|
913 |
} else { |
|
914 |
if (getTitle() == null) { |
|
915 |
return super.getAccessibleName(); |
|
916 |
} else { |
|
917 |
return getTitle(); |
|
918 |
} |
|
919 |
} |
|
920 |
} |
|
921 |
||
922 |
/** |
|
923 |
* Get the state of this object. |
|
924 |
* |
|
925 |
* @return an instance of AccessibleStateSet containing the current |
|
926 |
* state set of the object |
|
927 |
* @see AccessibleState |
|
928 |
*/ |
|
929 |
public AccessibleStateSet getAccessibleStateSet() { |
|
930 |
AccessibleStateSet states = super.getAccessibleStateSet(); |
|
931 |
||
932 |
if (isResizable()) { |
|
933 |
states.add(AccessibleState.RESIZABLE); |
|
934 |
} |
|
935 |
if (getFocusOwner() != null) { |
|
936 |
states.add(AccessibleState.ACTIVE); |
|
937 |
} |
|
938 |
// FIXME: [[[WDW - should also return ICONIFIED and ICONIFIABLE |
|
939 |
// if we can ever figure these out]]] |
|
940 |
return states; |
|
941 |
} |
|
942 |
} // inner class AccessibleJFrame |
|
943 |
} |