src/share/classes/javax/swing/JFrame.java

Print this page




  31 import java.awt.Frame;
  32 import java.awt.Graphics;
  33 import java.awt.GraphicsConfiguration;
  34 import java.awt.HeadlessException;
  35 import java.awt.Image;
  36 import java.awt.LayoutManager;
  37 import java.awt.event.WindowEvent;
  38 
  39 import javax.accessibility.Accessible;
  40 import javax.accessibility.AccessibleContext;
  41 import javax.accessibility.AccessibleState;
  42 import javax.accessibility.AccessibleStateSet;
  43 
  44 
  45 /**
  46  * An extended version of <code>java.awt.Frame</code> that adds support for
  47  * the JFC/Swing component architecture.
  48  * You can find task-oriented documentation about using <code>JFrame</code>
  49  * in <em>The Java Tutorial</em>, in the section
  50  * <a
  51  href="http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html">How to Make Frames</a>.
  52  *
  53  * <p>
  54  * The <code>JFrame</code> class is slightly incompatible with <code>Frame</code>.
  55  * Like all other JFC/Swing top-level containers,
  56  * a <code>JFrame</code> contains a <code>JRootPane</code> as its only child.
  57  * The <b>content pane</b> provided by the root pane should,
  58  * as a rule, contain
  59  * all the non-menu components displayed by the <code>JFrame</code>.
  60  * This is different from the AWT <code>Frame</code> case.
  61  * As a convenience, the {@code add}, {@code remove}, and {@code setLayout}
  62  * methods of this class are overridden, so that they delegate calls
  63  * to the corresponding methods of the {@code ContentPane}.
  64  * For example, you can add a child component to a frame as follows:
  65  * <pre>
  66  *       frame.add(child);
  67  * </pre>
  68  * And the child will be added to the contentPane.
  69  * The content pane will
  70  * always be non-null. Attempting to set it to null will cause the JFrame
  71  * to throw an exception. The default content pane will have a BorderLayout
  72  * manager set on it.
  73  * Refer to {@link javax.swing.RootPaneContainer}
  74  * for details on adding, removing and setting the <code>LayoutManager</code>
  75  * of a <code>JFrame</code>.
  76  * <p>
  77  * Unlike a <code>Frame</code>, a <code>JFrame</code> has some notion of how to
  78  * respond when the user attempts to close the window. The default behavior
  79  * is to simply hide the JFrame when the user closes the window. To change the
  80  * default behavior, you invoke the method
  81  * {@link #setDefaultCloseOperation}.
  82  * To make the <code>JFrame</code> behave the same as a <code>Frame</code>
  83  * instance, use
  84  * <code>setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)</code>.
  85  * <p>
  86  * For more information on content panes
  87  * and other features that root panes provide,
  88  * see <a
  89  href="http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html">Using Top-Level Containers</a> in <em>The Java Tutorial</em>.
  90  * <p>
  91  * In a multi-screen environment, you can create a <code>JFrame</code>
  92  * on a different screen device.  See {@link java.awt.Frame} for more
  93  * information.
  94  * <p>
  95  * <strong>Warning:</strong> Swing is not thread safe. For more
  96  * information see <a
  97  * href="package-summary.html#threading">Swing's Threading
  98  * Policy</a>.
  99  * <p>
 100  * <strong>Warning:</strong>
 101  * Serialized objects of this class will not be compatible with
 102  * future Swing releases. The current serialization support is
 103  * appropriate for short term storage or RMI between applications running
 104  * the same version of Swing.  As of 1.4, support for long term storage
 105  * of all JavaBeans&trade;
 106  * has been added to the <code>java.beans</code> package.
 107  * Please see {@link java.beans.XMLEncoder}.
 108  *
 109  * @see JRootPane


 417         return defaultCloseOperation;
 418     }
 419 
 420     /**
 421      * Sets the {@code transferHandler} property, which is a mechanism to
 422      * support transfer of data into this component. Use {@code null}
 423      * if the component does not support data transfer operations.
 424      * <p>
 425      * If the system property {@code suppressSwingDropSupport} is {@code false}
 426      * (the default) and the current drop target on this component is either
 427      * {@code null} or not a user-set drop target, this method will change the
 428      * drop target as follows: If {@code newHandler} is {@code null} it will
 429      * clear the drop target. If not {@code null} it will install a new
 430      * {@code DropTarget}.
 431      * <p>
 432      * Note: When used with {@code JFrame}, {@code TransferHandler} only
 433      * provides data import capability, as the data export related methods
 434      * are currently typed to {@code JComponent}.
 435      * <p>
 436      * Please see
 437      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
 438      * How to Use Drag and Drop and Data Transfer</a>, a section in
 439      * <em>The Java Tutorial</em>, for more information.
 440      *
 441      * @param newHandler the new {@code TransferHandler}
 442      *
 443      * @see TransferHandler
 444      * @see #getTransferHandler
 445      * @see java.awt.Component#setDropTarget
 446      * @since 1.6
 447      *
 448      * @beaninfo
 449      *        bound: true
 450      *       hidden: true
 451      *  description: Mechanism for transfer of data into the component
 452      */
 453     public void setTransferHandler(TransferHandler newHandler) {
 454         TransferHandler oldHandler = transferHandler;
 455         transferHandler = newHandler;
 456         SwingUtilities.installSwingDropTargetAsNecessary(this, transferHandler);
 457         firePropertyChange("transferHandler", oldHandler, newHandler);




  31 import java.awt.Frame;
  32 import java.awt.Graphics;
  33 import java.awt.GraphicsConfiguration;
  34 import java.awt.HeadlessException;
  35 import java.awt.Image;
  36 import java.awt.LayoutManager;
  37 import java.awt.event.WindowEvent;
  38 
  39 import javax.accessibility.Accessible;
  40 import javax.accessibility.AccessibleContext;
  41 import javax.accessibility.AccessibleState;
  42 import javax.accessibility.AccessibleStateSet;
  43 
  44 
  45 /**
  46  * An extended version of <code>java.awt.Frame</code> that adds support for
  47  * the JFC/Swing component architecture.
  48  * You can find task-oriented documentation about using <code>JFrame</code>
  49  * in <em>The Java Tutorial</em>, in the section
  50  * <a
  51  href="https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html">How to Make Frames</a>.
  52  *
  53  * <p>
  54  * The <code>JFrame</code> class is slightly incompatible with <code>Frame</code>.
  55  * Like all other JFC/Swing top-level containers,
  56  * a <code>JFrame</code> contains a <code>JRootPane</code> as its only child.
  57  * The <b>content pane</b> provided by the root pane should,
  58  * as a rule, contain
  59  * all the non-menu components displayed by the <code>JFrame</code>.
  60  * This is different from the AWT <code>Frame</code> case.
  61  * As a convenience, the {@code add}, {@code remove}, and {@code setLayout}
  62  * methods of this class are overridden, so that they delegate calls
  63  * to the corresponding methods of the {@code ContentPane}.
  64  * For example, you can add a child component to a frame as follows:
  65  * <pre>
  66  *       frame.add(child);
  67  * </pre>
  68  * And the child will be added to the contentPane.
  69  * The content pane will
  70  * always be non-null. Attempting to set it to null will cause the JFrame
  71  * to throw an exception. The default content pane will have a BorderLayout
  72  * manager set on it.
  73  * Refer to {@link javax.swing.RootPaneContainer}
  74  * for details on adding, removing and setting the <code>LayoutManager</code>
  75  * of a <code>JFrame</code>.
  76  * <p>
  77  * Unlike a <code>Frame</code>, a <code>JFrame</code> has some notion of how to
  78  * respond when the user attempts to close the window. The default behavior
  79  * is to simply hide the JFrame when the user closes the window. To change the
  80  * default behavior, you invoke the method
  81  * {@link #setDefaultCloseOperation}.
  82  * To make the <code>JFrame</code> behave the same as a <code>Frame</code>
  83  * instance, use
  84  * <code>setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)</code>.
  85  * <p>
  86  * For more information on content panes
  87  * and other features that root panes provide,
  88  * see <a
  89  href="https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html">Using Top-Level Containers</a> in <em>The Java Tutorial</em>.
  90  * <p>
  91  * In a multi-screen environment, you can create a <code>JFrame</code>
  92  * on a different screen device.  See {@link java.awt.Frame} for more
  93  * information.
  94  * <p>
  95  * <strong>Warning:</strong> Swing is not thread safe. For more
  96  * information see <a
  97  * href="package-summary.html#threading">Swing's Threading
  98  * Policy</a>.
  99  * <p>
 100  * <strong>Warning:</strong>
 101  * Serialized objects of this class will not be compatible with
 102  * future Swing releases. The current serialization support is
 103  * appropriate for short term storage or RMI between applications running
 104  * the same version of Swing.  As of 1.4, support for long term storage
 105  * of all JavaBeans&trade;
 106  * has been added to the <code>java.beans</code> package.
 107  * Please see {@link java.beans.XMLEncoder}.
 108  *
 109  * @see JRootPane


 417         return defaultCloseOperation;
 418     }
 419 
 420     /**
 421      * Sets the {@code transferHandler} property, which is a mechanism to
 422      * support transfer of data into this component. Use {@code null}
 423      * if the component does not support data transfer operations.
 424      * <p>
 425      * If the system property {@code suppressSwingDropSupport} is {@code false}
 426      * (the default) and the current drop target on this component is either
 427      * {@code null} or not a user-set drop target, this method will change the
 428      * drop target as follows: If {@code newHandler} is {@code null} it will
 429      * clear the drop target. If not {@code null} it will install a new
 430      * {@code DropTarget}.
 431      * <p>
 432      * Note: When used with {@code JFrame}, {@code TransferHandler} only
 433      * provides data import capability, as the data export related methods
 434      * are currently typed to {@code JComponent}.
 435      * <p>
 436      * Please see
 437      * <a href="https://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
 438      * How to Use Drag and Drop and Data Transfer</a>, a section in
 439      * <em>The Java Tutorial</em>, for more information.
 440      *
 441      * @param newHandler the new {@code TransferHandler}
 442      *
 443      * @see TransferHandler
 444      * @see #getTransferHandler
 445      * @see java.awt.Component#setDropTarget
 446      * @since 1.6
 447      *
 448      * @beaninfo
 449      *        bound: true
 450      *       hidden: true
 451      *  description: Mechanism for transfer of data into the component
 452      */
 453     public void setTransferHandler(TransferHandler newHandler) {
 454         TransferHandler oldHandler = transferHandler;
 455         transferHandler = newHandler;
 456         SwingUtilities.installSwingDropTargetAsNecessary(this, transferHandler);
 457         firePropertyChange("transferHandler", oldHandler, newHandler);