jdk/src/share/classes/javax/swing/JRootPane.java

Print this page




  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.applet.Applet;
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.beans.*;
  31 import java.security.AccessController;
  32 import javax.accessibility.*;
  33 import javax.swing.plaf.RootPaneUI;
  34 import java.util.Vector;
  35 import java.io.Serializable;
  36 import javax.swing.border.*;

  37 import sun.awt.AWTAccessor;
  38 import sun.security.action.GetBooleanAction;
  39 
  40 
  41 /**
  42  * A lightweight container used behind the scenes by
  43  * <code>JFrame</code>, <code>JDialog</code>, <code>JWindow</code>,
  44  * <code>JApplet</code>, and <code>JInternalFrame</code>.
  45  * For task-oriented information on functionality provided by root panes
  46  * see <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html">How to Use Root Panes</a>,
  47  * a section in <em>The Java Tutorial</em>.
  48  *
  49  * <p>
  50  * The following image shows the relationships between
  51  * the classes that use root panes.
  52  * <p style="text-align:center"><img src="doc-files/JRootPane-1.gif"
  53  * alt="The following text describes this graphic."
  54  * HEIGHT=484 WIDTH=629></p>
  55  * The &quot;heavyweight&quot; components (those that delegate to a peer, or native
  56  * component on the host system) are shown with a darker, heavier box. The four


 404      * closing a Window, title ...) the <code>JRootPane</code> should
 405      * provide. The default is to provide no Window decorations
 406      * (<code>NONE</code>).
 407      * <p>
 408      * This is only a hint, and some look and feels may not support
 409      * this.
 410      * This is a bound property.
 411      *
 412      * @param windowDecorationStyle Constant identifying Window decorations
 413      *        to provide.
 414      * @see JDialog#setDefaultLookAndFeelDecorated
 415      * @see JFrame#setDefaultLookAndFeelDecorated
 416      * @see LookAndFeel#getSupportsWindowDecorations
 417      * @throws IllegalArgumentException if <code>style</code> is
 418      *        not one of: <code>NONE</code>, <code>FRAME</code>,
 419      *        <code>PLAIN_DIALOG</code>, <code>INFORMATION_DIALOG</code>,
 420      *        <code>ERROR_DIALOG</code>, <code>COLOR_CHOOSER_DIALOG</code>,
 421      *        <code>FILE_CHOOSER_DIALOG</code>, <code>QUESTION_DIALOG</code>, or
 422      *        <code>WARNING_DIALOG</code>.
 423      * @since 1.4
 424      * @beaninfo
 425      *        bound: true
 426      *         enum: NONE                   JRootPane.NONE
 427      *               FRAME                  JRootPane.FRAME
 428      *               PLAIN_DIALOG           JRootPane.PLAIN_DIALOG
 429      *               INFORMATION_DIALOG     JRootPane.INFORMATION_DIALOG
 430      *               ERROR_DIALOG           JRootPane.ERROR_DIALOG
 431      *               COLOR_CHOOSER_DIALOG   JRootPane.COLOR_CHOOSER_DIALOG
 432      *               FILE_CHOOSER_DIALOG    JRootPane.FILE_CHOOSER_DIALOG
 433      *               QUESTION_DIALOG        JRootPane.QUESTION_DIALOG
 434      *               WARNING_DIALOG         JRootPane.WARNING_DIALOG
 435      *       expert: true
 436      *    attribute: visualUpdate true
 437      *  description: Identifies the type of Window decorations to provide
 438      */











 439     public void setWindowDecorationStyle(int windowDecorationStyle) {
 440         if (windowDecorationStyle < 0 ||
 441                   windowDecorationStyle > WARNING_DIALOG) {
 442             throw new IllegalArgumentException("Invalid decoration style");
 443         }
 444         int oldWindowDecorationStyle = getWindowDecorationStyle();
 445         this.windowDecorationStyle = windowDecorationStyle;
 446         firePropertyChange("windowDecorationStyle",
 447                             oldWindowDecorationStyle,
 448                             windowDecorationStyle);
 449     }
 450 
 451     /**
 452      * Returns the L&amp;F object that renders this component.
 453      *
 454      * @return <code>LabelUI</code> object
 455      * @since 1.3
 456      */
 457     public RootPaneUI getUI() {
 458         return (RootPaneUI)ui;
 459     }
 460 
 461     /**
 462      * Sets the L&amp;F object that renders this component.
 463      *
 464      * @param ui  the <code>LabelUI</code> L&amp;F object
 465      * @see UIDefaults#getUI
 466      * @beaninfo
 467      *        bound: true
 468      *       hidden: true
 469      *      expert: true
 470      *    attribute: visualUpdate true
 471      *  description: The UI object that implements the Component's LookAndFeel.
 472      * @since 1.3
 473      */


 474     public void setUI(RootPaneUI ui) {
 475         super.setUI(ui);
 476     }
 477 
 478 
 479     /**
 480      * Resets the UI property to a value from the current look and feel.
 481      *
 482      * @see JComponent#updateUI
 483      */
 484     public void updateUI() {
 485         setUI((RootPaneUI)UIManager.getUI(this));
 486     }
 487 
 488 
 489     /**
 490      * Returns a string that specifies the name of the L&amp;F class
 491      * that renders this component.
 492      *
 493      * @return the string "RootPaneUI"


 766         super.removeNotify();
 767     }
 768 
 769 
 770     /**
 771      * Sets the <code>defaultButton</code> property,
 772      * which determines the current default button for this <code>JRootPane</code>.
 773      * The default button is the button which will be activated
 774      * when a UI-defined activation event (typically the <b>Enter</b> key)
 775      * occurs in the root pane regardless of whether or not the button
 776      * has keyboard focus (unless there is another component within
 777      * the root pane which consumes the activation event,
 778      * such as a <code>JTextPane</code>).
 779      * For default activation to work, the button must be an enabled
 780      * descendent of the root pane when activation occurs.
 781      * To remove a default button from this root pane, set this
 782      * property to <code>null</code>.
 783      *
 784      * @see JButton#isDefaultButton
 785      * @param defaultButton the <code>JButton</code> which is to be the default button
 786      *
 787      * @beaninfo
 788      *  description: The button activated by default in this root pane
 789      */


 790     public void setDefaultButton(JButton defaultButton) {
 791         JButton oldDefault = this.defaultButton;
 792 
 793         if (oldDefault != defaultButton) {
 794             this.defaultButton = defaultButton;
 795 
 796             if (oldDefault != null) {
 797                 oldDefault.repaint();
 798             }
 799             if (defaultButton != null) {
 800                 defaultButton.repaint();
 801             }
 802         }
 803 
 804         firePropertyChange("defaultButton", oldDefault, defaultButton);
 805     }
 806 
 807     /**
 808      * Returns the value of the <code>defaultButton</code> property.
 809      * @return the <code>JButton</code> which is currently the default button




  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.applet.Applet;
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.beans.*;
  31 import java.security.AccessController;
  32 import javax.accessibility.*;
  33 import javax.swing.plaf.RootPaneUI;
  34 import java.util.Vector;
  35 import java.io.Serializable;
  36 import javax.swing.border.*;
  37 
  38 import sun.awt.AWTAccessor;
  39 import sun.security.action.GetBooleanAction;
  40 
  41 
  42 /**
  43  * A lightweight container used behind the scenes by
  44  * <code>JFrame</code>, <code>JDialog</code>, <code>JWindow</code>,
  45  * <code>JApplet</code>, and <code>JInternalFrame</code>.
  46  * For task-oriented information on functionality provided by root panes
  47  * see <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html">How to Use Root Panes</a>,
  48  * a section in <em>The Java Tutorial</em>.
  49  *
  50  * <p>
  51  * The following image shows the relationships between
  52  * the classes that use root panes.
  53  * <p style="text-align:center"><img src="doc-files/JRootPane-1.gif"
  54  * alt="The following text describes this graphic."
  55  * HEIGHT=484 WIDTH=629></p>
  56  * The &quot;heavyweight&quot; components (those that delegate to a peer, or native
  57  * component on the host system) are shown with a darker, heavier box. The four


 405      * closing a Window, title ...) the <code>JRootPane</code> should
 406      * provide. The default is to provide no Window decorations
 407      * (<code>NONE</code>).
 408      * <p>
 409      * This is only a hint, and some look and feels may not support
 410      * this.
 411      * This is a bound property.
 412      *
 413      * @param windowDecorationStyle Constant identifying Window decorations
 414      *        to provide.
 415      * @see JDialog#setDefaultLookAndFeelDecorated
 416      * @see JFrame#setDefaultLookAndFeelDecorated
 417      * @see LookAndFeel#getSupportsWindowDecorations
 418      * @throws IllegalArgumentException if <code>style</code> is
 419      *        not one of: <code>NONE</code>, <code>FRAME</code>,
 420      *        <code>PLAIN_DIALOG</code>, <code>INFORMATION_DIALOG</code>,
 421      *        <code>ERROR_DIALOG</code>, <code>COLOR_CHOOSER_DIALOG</code>,
 422      *        <code>FILE_CHOOSER_DIALOG</code>, <code>QUESTION_DIALOG</code>, or
 423      *        <code>WARNING_DIALOG</code>.
 424      * @since 1.4














 425      */
 426     @BeanProperty(expert = true, visualUpdate = true, enumerationValues = {
 427             "JRootPane.NONE",
 428             "JRootPane.FRAME",
 429             "JRootPane.PLAIN_DIALOG",
 430             "JRootPane.INFORMATION_DIALOG",
 431             "JRootPane.ERROR_DIALOG",
 432             "JRootPane.COLOR_CHOOSER_DIALOG",
 433             "JRootPane.FILE_CHOOSER_DIALOG",
 434             "JRootPane.QUESTION_DIALOG",
 435             "JRootPane.WARNING_DIALOG"}, description
 436             = "Identifies the type of Window decorations to provide")
 437     public void setWindowDecorationStyle(int windowDecorationStyle) {
 438         if (windowDecorationStyle < 0 ||
 439                   windowDecorationStyle > WARNING_DIALOG) {
 440             throw new IllegalArgumentException("Invalid decoration style");
 441         }
 442         int oldWindowDecorationStyle = getWindowDecorationStyle();
 443         this.windowDecorationStyle = windowDecorationStyle;
 444         firePropertyChange("windowDecorationStyle",
 445                             oldWindowDecorationStyle,
 446                             windowDecorationStyle);
 447     }
 448 
 449     /**
 450      * Returns the L&amp;F object that renders this component.
 451      *
 452      * @return <code>LabelUI</code> object
 453      * @since 1.3
 454      */
 455     public RootPaneUI getUI() {
 456         return (RootPaneUI)ui;
 457     }
 458 
 459     /**
 460      * Sets the L&amp;F object that renders this component.
 461      *
 462      * @param ui  the <code>LabelUI</code> L&amp;F object
 463      * @see UIDefaults#getUI






 464      * @since 1.3
 465      */
 466     @BeanProperty(expert = true, hidden = true, visualUpdate = true, description
 467             = "The UI object that implements the Component's LookAndFeel.")
 468     public void setUI(RootPaneUI ui) {
 469         super.setUI(ui);
 470     }
 471 
 472 
 473     /**
 474      * Resets the UI property to a value from the current look and feel.
 475      *
 476      * @see JComponent#updateUI
 477      */
 478     public void updateUI() {
 479         setUI((RootPaneUI)UIManager.getUI(this));
 480     }
 481 
 482 
 483     /**
 484      * Returns a string that specifies the name of the L&amp;F class
 485      * that renders this component.
 486      *
 487      * @return the string "RootPaneUI"


 760         super.removeNotify();
 761     }
 762 
 763 
 764     /**
 765      * Sets the <code>defaultButton</code> property,
 766      * which determines the current default button for this <code>JRootPane</code>.
 767      * The default button is the button which will be activated
 768      * when a UI-defined activation event (typically the <b>Enter</b> key)
 769      * occurs in the root pane regardless of whether or not the button
 770      * has keyboard focus (unless there is another component within
 771      * the root pane which consumes the activation event,
 772      * such as a <code>JTextPane</code>).
 773      * For default activation to work, the button must be an enabled
 774      * descendent of the root pane when activation occurs.
 775      * To remove a default button from this root pane, set this
 776      * property to <code>null</code>.
 777      *
 778      * @see JButton#isDefaultButton
 779      * @param defaultButton the <code>JButton</code> which is to be the default button



 780      */
 781     @BeanProperty(description
 782             = "The button activated by default in this root pane")
 783     public void setDefaultButton(JButton defaultButton) {
 784         JButton oldDefault = this.defaultButton;
 785 
 786         if (oldDefault != defaultButton) {
 787             this.defaultButton = defaultButton;
 788 
 789             if (oldDefault != null) {
 790                 oldDefault.repaint();
 791             }
 792             if (defaultButton != null) {
 793                 defaultButton.repaint();
 794             }
 795         }
 796 
 797         firePropertyChange("defaultButton", oldDefault, defaultButton);
 798     }
 799 
 800     /**
 801      * Returns the value of the <code>defaultButton</code> property.
 802      * @return the <code>JButton</code> which is currently the default button