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

Print this page




  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://java.sun.com/docs/books/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://java.sun.com/docs/books/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


 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://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.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);




  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


 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);