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