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 javax.accessibility.*; 30 31 /** 32 * The main class for creating a dialog window. You can use this class 33 * to create a custom dialog, or invoke the many class methods 34 * in {@link JOptionPane} to create a variety of standard dialogs. 35 * For information about creating dialogs, see 36 * <em>The Java Tutorial</em> section 37 * <a 38 href="http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html">How 39 * to Make Dialogs</a>. 40 * 41 * <p> 42 * 43 * The {@code JDialog} component contains a {@code JRootPane} 44 * as its only child. 45 * The {@code contentPane} should be the parent of any children of the 46 * {@code JDialog}. 47 * As a convenience, the {@code add}, {@code remove}, and {@code setLayout} 48 * methods of this class are overridden, so that they delegate calls 69 * more information. 70 * <p> 71 * <strong>Warning:</strong> Swing is not thread safe. For more 72 * information see <a 73 * href="package-summary.html#threading">Swing's Threading 74 * Policy</a>. 75 * <p> 76 * <strong>Warning:</strong> 77 * Serialized objects of this class will not be compatible with 78 * future Swing releases. The current serialization support is 79 * appropriate for short term storage or RMI between applications running 80 * the same version of Swing. As of 1.4, support for long term storage 81 * of all JavaBeans™ 82 * has been added to the {@code java.beans} package. 83 * Please see {@link java.beans.XMLEncoder}. 84 * 85 * @see JOptionPane 86 * @see JRootPane 87 * @see javax.swing.RootPaneContainer 88 * 89 * @beaninfo 90 * attribute: isContainer true 91 * attribute: containerDelegate getContentPane 92 * description: A toplevel window for creating dialog boxes. 93 * 94 * @author David Kloba 95 * @author James Gosling 96 * @author Scott Violet 97 * @since 1.2 98 */ 99 @SuppressWarnings("serial") // Same-version serialization only 100 public class JDialog extends Dialog implements WindowConstants, 101 Accessible, 102 RootPaneContainer, 103 TransferHandler.HasGetTransferHandler 104 { 105 /** 106 * Key into the AppContext, used to check if should provide decorations 107 * by default. 108 */ 109 private static final Object defaultLookAndFeelDecoratedKey = 110 new StringBuffer("JDialog.defaultLookAndFeelDecorated"); 111 112 private int defaultCloseOperation = HIDE_ON_CLOSE; 113 114 /** 115 * @see #getRootPane 116 * @see #setRootPane 117 */ 118 protected JRootPane rootPane; 726 * dialog after invoking any registered {@code WindowListener} 727 * objects. 728 * </ul> 729 * <p> 730 * The value is set to {@code HIDE_ON_CLOSE} by default. Changes 731 * to the value of this property cause the firing of a property 732 * change event, with property name "defaultCloseOperation". 733 * <p> 734 * <b>Note</b>: When the last displayable window within the 735 * Java virtual machine (VM) is disposed of, the VM may 736 * terminate. See <a href="../../java/awt/doc-files/AWTThreadIssues.html"> 737 * AWT Threading Issues</a> for more information. 738 * 739 * @param operation the operation which should be performed when the 740 * user closes the dialog 741 * @throws IllegalArgumentException if defaultCloseOperation value 742 * isn't one of the above valid values 743 * @see #addWindowListener 744 * @see #getDefaultCloseOperation 745 * @see WindowConstants 746 * 747 * @beaninfo 748 * preferred: true 749 * bound: true 750 * enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE 751 * HIDE_ON_CLOSE WindowConstants.HIDE_ON_CLOSE 752 * DISPOSE_ON_CLOSE WindowConstants.DISPOSE_ON_CLOSE 753 * description: The dialog's default close operation. 754 */ 755 public void setDefaultCloseOperation(int operation) { 756 if (operation != DO_NOTHING_ON_CLOSE && 757 operation != HIDE_ON_CLOSE && 758 operation != DISPOSE_ON_CLOSE) { 759 throw new IllegalArgumentException("defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE"); 760 } 761 762 int oldValue = this.defaultCloseOperation; 763 this.defaultCloseOperation = operation; 764 firePropertyChange("defaultCloseOperation", oldValue, operation); 765 } 766 767 /** 768 * Returns the operation which occurs when the user 769 * initiates a "close" on this dialog. 770 * 771 * @return an integer indicating the window-close operation 772 * @see #setDefaultCloseOperation 773 */ 774 public int getDefaultCloseOperation() { 785 * {@code null} or not a user-set drop target, this method will change the 786 * drop target as follows: If {@code newHandler} is {@code null} it will 787 * clear the drop target. If not {@code null} it will install a new 788 * {@code DropTarget}. 789 * <p> 790 * Note: When used with {@code JDialog}, {@code TransferHandler} only 791 * provides data import capability, as the data export related methods 792 * are currently typed to {@code JComponent}. 793 * <p> 794 * Please see 795 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html"> 796 * How to Use Drag and Drop and Data Transfer</a>, a section in 797 * <em>The Java Tutorial</em>, for more information. 798 * 799 * @param newHandler the new {@code TransferHandler} 800 * 801 * @see TransferHandler 802 * @see #getTransferHandler 803 * @see java.awt.Component#setDropTarget 804 * @since 1.6 805 * 806 * @beaninfo 807 * bound: true 808 * hidden: true 809 * description: Mechanism for transfer of data into the component 810 */ 811 public void setTransferHandler(TransferHandler newHandler) { 812 TransferHandler oldHandler = transferHandler; 813 transferHandler = newHandler; 814 SwingUtilities.installSwingDropTargetAsNecessary(this, transferHandler); 815 firePropertyChange("transferHandler", oldHandler, newHandler); 816 } 817 818 /** 819 * Gets the {@code transferHandler} property. 820 * 821 * @return the value of the {@code transferHandler} property 822 * 823 * @see TransferHandler 824 * @see #setTransferHandler 825 * @since 1.6 826 */ 827 public TransferHandler getTransferHandler() { 828 return transferHandler; 829 } 830 831 /** 832 * Calls {@code paint(g)}. This method was overridden to 833 * prevent an unnecessary call to clear the background. 834 * 835 * @param g the {@code Graphics} context in which to paint 836 */ 837 public void update(Graphics g) { 838 paint(g); 839 } 840 841 /** 842 * Sets the menubar for this dialog. 843 * 844 * @param menu the menubar being placed in the dialog 845 * 846 * @see #getJMenuBar 847 * 848 * @beaninfo 849 * hidden: true 850 * description: The menubar for accessing pulldown menus from this dialog. 851 */ 852 public void setJMenuBar(JMenuBar menu) { 853 getRootPane().setMenuBar(menu); 854 } 855 856 /** 857 * Returns the menubar set on this dialog. 858 * 859 * @return the menubar set on this dialog 860 * @see #setJMenuBar 861 */ 862 public JMenuBar getJMenuBar() { 863 return getRootPane().getMenuBar(); 864 } 865 866 867 /** 868 * Returns whether calls to {@code add} and 869 * {@code setLayout} are forwarded to the {@code contentPane}. 870 * 871 * @return true if {@code add} and {@code setLayout} 876 * @see #setRootPaneCheckingEnabled 877 * @see javax.swing.RootPaneContainer 878 */ 879 protected boolean isRootPaneCheckingEnabled() { 880 return rootPaneCheckingEnabled; 881 } 882 883 884 /** 885 * Sets whether calls to {@code add} and 886 * {@code setLayout} are forwarded to the {@code contentPane}. 887 * 888 * @param enabled true if {@code add} and {@code setLayout} 889 * are forwarded, false if they should operate directly on the 890 * {@code JDialog}. 891 * 892 * @see #addImpl 893 * @see #setLayout 894 * @see #isRootPaneCheckingEnabled 895 * @see javax.swing.RootPaneContainer 896 * @beaninfo 897 * hidden: true 898 * description: Whether the add and setLayout methods are forwarded 899 */ 900 protected void setRootPaneCheckingEnabled(boolean enabled) { 901 rootPaneCheckingEnabled = enabled; 902 } 903 904 /** 905 * Adds the specified child {@code Component}. 906 * This method is overridden to conditionally forward calls to the 907 * {@code contentPane}. 908 * By default, children are added to the {@code contentPane} instead 909 * of the frame, refer to {@link javax.swing.RootPaneContainer} for 910 * details. 911 * 912 * @param comp the component to be enhanced 913 * @param constraints the constraints to be respected 914 * @param index the index 915 * @throws IllegalArgumentException if {@code index} is invalid 916 * @throws IllegalArgumentException if adding the container's parent 917 * to itself 918 * @throws IllegalArgumentException if adding a window to a container 919 * 961 * @param manager the {@code LayoutManager} 962 * @see #setRootPaneCheckingEnabled 963 * @see javax.swing.RootPaneContainer 964 */ 965 public void setLayout(LayoutManager manager) { 966 if(isRootPaneCheckingEnabled()) { 967 getContentPane().setLayout(manager); 968 } 969 else { 970 super.setLayout(manager); 971 } 972 } 973 974 975 /** 976 * Returns the {@code rootPane} object for this dialog. 977 * 978 * @see #setRootPane 979 * @see RootPaneContainer#getRootPane 980 */ 981 public JRootPane getRootPane() { 982 return rootPane; 983 } 984 985 986 /** 987 * Sets the {@code rootPane} property. 988 * This method is called by the constructor. 989 * 990 * @param root the {@code rootPane} object for this dialog 991 * 992 * @see #getRootPane 993 * 994 * @beaninfo 995 * hidden: true 996 * description: the RootPane object for this dialog. 997 */ 998 protected void setRootPane(JRootPane root) { 999 if(rootPane != null) { 1000 remove(rootPane); 1001 } 1002 rootPane = root; 1003 if(rootPane != null) { 1004 boolean checkingEnabled = isRootPaneCheckingEnabled(); 1005 try { 1006 setRootPaneCheckingEnabled(false); 1007 add(rootPane, BorderLayout.CENTER); 1008 } 1009 finally { 1010 setRootPaneCheckingEnabled(checkingEnabled); 1011 } 1012 } 1013 } 1014 1015 1016 /** 1025 return getRootPane().getContentPane(); 1026 } 1027 1028 1029 /** 1030 * Sets the {@code contentPane} property. 1031 * This method is called by the constructor. 1032 * <p> 1033 * Swing's painting architecture requires an opaque {@code JComponent} 1034 * in the containment hierarchy. This is typically provided by the 1035 * content pane. If you replace the content pane it is recommended you 1036 * replace it with an opaque {@code JComponent}. 1037 * @see JRootPane 1038 * 1039 * @param contentPane the {@code contentPane} object for this dialog 1040 * 1041 * @throws java.awt.IllegalComponentStateException (a runtime 1042 * exception) if the content pane parameter is {@code null} 1043 * @see #getContentPane 1044 * @see RootPaneContainer#setContentPane 1045 * 1046 * @beaninfo 1047 * hidden: true 1048 * description: The client area of the dialog where child 1049 * components are normally inserted. 1050 */ 1051 public void setContentPane(Container contentPane) { 1052 getRootPane().setContentPane(contentPane); 1053 } 1054 1055 /** 1056 * Returns the {@code layeredPane} object for this dialog. 1057 * 1058 * @return the {@code layeredPane} property 1059 * 1060 * @see #setLayeredPane 1061 * @see RootPaneContainer#getLayeredPane 1062 */ 1063 public JLayeredPane getLayeredPane() { 1064 return getRootPane().getLayeredPane(); 1065 } 1066 1067 /** 1068 * Sets the {@code layeredPane} property. 1069 * This method is called by the constructor. 1070 * 1071 * @param layeredPane the new {@code layeredPane} property 1072 * 1073 * @throws java.awt.IllegalComponentStateException (a runtime 1074 * exception) if the layered pane parameter is null 1075 * @see #getLayeredPane 1076 * @see RootPaneContainer#setLayeredPane 1077 * 1078 * @beaninfo 1079 * hidden: true 1080 * description: The pane which holds the various dialog layers. 1081 */ 1082 public void setLayeredPane(JLayeredPane layeredPane) { 1083 getRootPane().setLayeredPane(layeredPane); 1084 } 1085 1086 /** 1087 * Returns the {@code glassPane} object for this dialog. 1088 * 1089 * @return the {@code glassPane} property 1090 * 1091 * @see #setGlassPane 1092 * @see RootPaneContainer#getGlassPane 1093 */ 1094 public Component getGlassPane() { 1095 return getRootPane().getGlassPane(); 1096 } 1097 1098 /** 1099 * Sets the {@code glassPane} property. 1100 * This method is called by the constructor. 1101 * 1102 * @param glassPane the {@code glassPane} object for this dialog 1103 * @see #getGlassPane 1104 * @see RootPaneContainer#setGlassPane 1105 * 1106 * @beaninfo 1107 * hidden: true 1108 * description: A transparent pane used for menu rendering. 1109 */ 1110 public void setGlassPane(Component glassPane) { 1111 getRootPane().setGlassPane(glassPane); 1112 } 1113 1114 /** 1115 * {@inheritDoc} 1116 * 1117 * @since 1.6 1118 */ 1119 public Graphics getGraphics() { 1120 JComponent.getGraphicsInvoked(this); 1121 return super.getGraphics(); 1122 } 1123 1124 /** 1125 * Repaints the specified rectangle of this component within 1126 * {@code time} milliseconds. Refer to {@code RepaintManager} 1127 * for details on how the repaint is handled. 1128 * 1129 * @param time maximum time in milliseconds before update 1130 * @param x the <i>x</i> coordinate 1131 * @param y the <i>y</i> coordinate 1132 * @param width the width 1133 * @param height the height 1134 * @see RepaintManager 1135 * @since 1.6 1136 */ 1137 public void repaint(long time, int x, int y, int width, int height) { 1138 if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) { | 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.JavaBean; 30 import java.beans.BeanProperty; 31 import javax.accessibility.*; 32 33 /** 34 * The main class for creating a dialog window. You can use this class 35 * to create a custom dialog, or invoke the many class methods 36 * in {@link JOptionPane} to create a variety of standard dialogs. 37 * For information about creating dialogs, see 38 * <em>The Java Tutorial</em> section 39 * <a 40 href="http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html">How 41 * to Make Dialogs</a>. 42 * 43 * <p> 44 * 45 * The {@code JDialog} component contains a {@code JRootPane} 46 * as its only child. 47 * The {@code contentPane} should be the parent of any children of the 48 * {@code JDialog}. 49 * As a convenience, the {@code add}, {@code remove}, and {@code setLayout} 50 * methods of this class are overridden, so that they delegate calls 71 * more information. 72 * <p> 73 * <strong>Warning:</strong> Swing is not thread safe. For more 74 * information see <a 75 * href="package-summary.html#threading">Swing's Threading 76 * Policy</a>. 77 * <p> 78 * <strong>Warning:</strong> 79 * Serialized objects of this class will not be compatible with 80 * future Swing releases. The current serialization support is 81 * appropriate for short term storage or RMI between applications running 82 * the same version of Swing. As of 1.4, support for long term storage 83 * of all JavaBeans™ 84 * has been added to the {@code java.beans} package. 85 * Please see {@link java.beans.XMLEncoder}. 86 * 87 * @see JOptionPane 88 * @see JRootPane 89 * @see javax.swing.RootPaneContainer 90 * 91 * @author David Kloba 92 * @author James Gosling 93 * @author Scott Violet 94 * @since 1.2 95 */ 96 @JavaBean(defaultProperty = "JMenuBar", description = "A toplevel window for creating dialog boxes.") 97 @SwingContainer(delegate = "getContentPane") 98 @SuppressWarnings("serial") // Same-version serialization only 99 public class JDialog extends Dialog implements WindowConstants, 100 Accessible, 101 RootPaneContainer, 102 TransferHandler.HasGetTransferHandler 103 { 104 /** 105 * Key into the AppContext, used to check if should provide decorations 106 * by default. 107 */ 108 private static final Object defaultLookAndFeelDecoratedKey = 109 new StringBuffer("JDialog.defaultLookAndFeelDecorated"); 110 111 private int defaultCloseOperation = HIDE_ON_CLOSE; 112 113 /** 114 * @see #getRootPane 115 * @see #setRootPane 116 */ 117 protected JRootPane rootPane; 725 * dialog after invoking any registered {@code WindowListener} 726 * objects. 727 * </ul> 728 * <p> 729 * The value is set to {@code HIDE_ON_CLOSE} by default. Changes 730 * to the value of this property cause the firing of a property 731 * change event, with property name "defaultCloseOperation". 732 * <p> 733 * <b>Note</b>: When the last displayable window within the 734 * Java virtual machine (VM) is disposed of, the VM may 735 * terminate. See <a href="../../java/awt/doc-files/AWTThreadIssues.html"> 736 * AWT Threading Issues</a> for more information. 737 * 738 * @param operation the operation which should be performed when the 739 * user closes the dialog 740 * @throws IllegalArgumentException if defaultCloseOperation value 741 * isn't one of the above valid values 742 * @see #addWindowListener 743 * @see #getDefaultCloseOperation 744 * @see WindowConstants 745 */ 746 @BeanProperty(preferred = true, enumerationValues = { 747 "WindowConstants.DO_NOTHING_ON_CLOSE", 748 "WindowConstants.HIDE_ON_CLOSE", 749 "WindowConstants.DISPOSE_ON_CLOSE"}, description 750 = "The dialog's default close operation.") 751 public void setDefaultCloseOperation(int operation) { 752 if (operation != DO_NOTHING_ON_CLOSE && 753 operation != HIDE_ON_CLOSE && 754 operation != DISPOSE_ON_CLOSE) { 755 throw new IllegalArgumentException("defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE"); 756 } 757 758 int oldValue = this.defaultCloseOperation; 759 this.defaultCloseOperation = operation; 760 firePropertyChange("defaultCloseOperation", oldValue, operation); 761 } 762 763 /** 764 * Returns the operation which occurs when the user 765 * initiates a "close" on this dialog. 766 * 767 * @return an integer indicating the window-close operation 768 * @see #setDefaultCloseOperation 769 */ 770 public int getDefaultCloseOperation() { 781 * {@code null} or not a user-set drop target, this method will change the 782 * drop target as follows: If {@code newHandler} is {@code null} it will 783 * clear the drop target. If not {@code null} it will install a new 784 * {@code DropTarget}. 785 * <p> 786 * Note: When used with {@code JDialog}, {@code TransferHandler} only 787 * provides data import capability, as the data export related methods 788 * are currently typed to {@code JComponent}. 789 * <p> 790 * Please see 791 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html"> 792 * How to Use Drag and Drop and Data Transfer</a>, a section in 793 * <em>The Java Tutorial</em>, for more information. 794 * 795 * @param newHandler the new {@code TransferHandler} 796 * 797 * @see TransferHandler 798 * @see #getTransferHandler 799 * @see java.awt.Component#setDropTarget 800 * @since 1.6 801 */ 802 @BeanProperty(hidden = true, description 803 = "Mechanism for transfer of data into the component") 804 public void setTransferHandler(TransferHandler newHandler) { 805 TransferHandler oldHandler = transferHandler; 806 transferHandler = newHandler; 807 SwingUtilities.installSwingDropTargetAsNecessary(this, transferHandler); 808 firePropertyChange("transferHandler", oldHandler, newHandler); 809 } 810 811 /** 812 * Gets the {@code transferHandler} property. 813 * 814 * @return the value of the {@code transferHandler} property 815 * 816 * @see TransferHandler 817 * @see #setTransferHandler 818 * @since 1.6 819 */ 820 public TransferHandler getTransferHandler() { 821 return transferHandler; 822 } 823 824 /** 825 * Calls {@code paint(g)}. This method was overridden to 826 * prevent an unnecessary call to clear the background. 827 * 828 * @param g the {@code Graphics} context in which to paint 829 */ 830 public void update(Graphics g) { 831 paint(g); 832 } 833 834 /** 835 * Sets the menubar for this dialog. 836 * 837 * @param menu the menubar being placed in the dialog 838 * 839 * @see #getJMenuBar 840 */ 841 @BeanProperty(bound = false, hidden = true, description 842 = "The menubar for accessing pulldown menus from this dialog.") 843 public void setJMenuBar(JMenuBar menu) { 844 getRootPane().setMenuBar(menu); 845 } 846 847 /** 848 * Returns the menubar set on this dialog. 849 * 850 * @return the menubar set on this dialog 851 * @see #setJMenuBar 852 */ 853 public JMenuBar getJMenuBar() { 854 return getRootPane().getMenuBar(); 855 } 856 857 858 /** 859 * Returns whether calls to {@code add} and 860 * {@code setLayout} are forwarded to the {@code contentPane}. 861 * 862 * @return true if {@code add} and {@code setLayout} 867 * @see #setRootPaneCheckingEnabled 868 * @see javax.swing.RootPaneContainer 869 */ 870 protected boolean isRootPaneCheckingEnabled() { 871 return rootPaneCheckingEnabled; 872 } 873 874 875 /** 876 * Sets whether calls to {@code add} and 877 * {@code setLayout} are forwarded to the {@code contentPane}. 878 * 879 * @param enabled true if {@code add} and {@code setLayout} 880 * are forwarded, false if they should operate directly on the 881 * {@code JDialog}. 882 * 883 * @see #addImpl 884 * @see #setLayout 885 * @see #isRootPaneCheckingEnabled 886 * @see javax.swing.RootPaneContainer 887 */ 888 @BeanProperty(hidden = true, description 889 = "Whether the add and setLayout methods are forwarded") 890 protected void setRootPaneCheckingEnabled(boolean enabled) { 891 rootPaneCheckingEnabled = enabled; 892 } 893 894 /** 895 * Adds the specified child {@code Component}. 896 * This method is overridden to conditionally forward calls to the 897 * {@code contentPane}. 898 * By default, children are added to the {@code contentPane} instead 899 * of the frame, refer to {@link javax.swing.RootPaneContainer} for 900 * details. 901 * 902 * @param comp the component to be enhanced 903 * @param constraints the constraints to be respected 904 * @param index the index 905 * @throws IllegalArgumentException if {@code index} is invalid 906 * @throws IllegalArgumentException if adding the container's parent 907 * to itself 908 * @throws IllegalArgumentException if adding a window to a container 909 * 951 * @param manager the {@code LayoutManager} 952 * @see #setRootPaneCheckingEnabled 953 * @see javax.swing.RootPaneContainer 954 */ 955 public void setLayout(LayoutManager manager) { 956 if(isRootPaneCheckingEnabled()) { 957 getContentPane().setLayout(manager); 958 } 959 else { 960 super.setLayout(manager); 961 } 962 } 963 964 965 /** 966 * Returns the {@code rootPane} object for this dialog. 967 * 968 * @see #setRootPane 969 * @see RootPaneContainer#getRootPane 970 */ 971 @BeanProperty(bound = false, hidden = true, description 972 = "the RootPane object for this dialog.") 973 public JRootPane getRootPane() { 974 return rootPane; 975 } 976 977 978 /** 979 * Sets the {@code rootPane} property. 980 * This method is called by the constructor. 981 * 982 * @param root the {@code rootPane} object for this dialog 983 * 984 * @see #getRootPane 985 */ 986 protected void setRootPane(JRootPane root) { 987 if(rootPane != null) { 988 remove(rootPane); 989 } 990 rootPane = root; 991 if(rootPane != null) { 992 boolean checkingEnabled = isRootPaneCheckingEnabled(); 993 try { 994 setRootPaneCheckingEnabled(false); 995 add(rootPane, BorderLayout.CENTER); 996 } 997 finally { 998 setRootPaneCheckingEnabled(checkingEnabled); 999 } 1000 } 1001 } 1002 1003 1004 /** 1013 return getRootPane().getContentPane(); 1014 } 1015 1016 1017 /** 1018 * Sets the {@code contentPane} property. 1019 * This method is called by the constructor. 1020 * <p> 1021 * Swing's painting architecture requires an opaque {@code JComponent} 1022 * in the containment hierarchy. This is typically provided by the 1023 * content pane. If you replace the content pane it is recommended you 1024 * replace it with an opaque {@code JComponent}. 1025 * @see JRootPane 1026 * 1027 * @param contentPane the {@code contentPane} object for this dialog 1028 * 1029 * @throws java.awt.IllegalComponentStateException (a runtime 1030 * exception) if the content pane parameter is {@code null} 1031 * @see #getContentPane 1032 * @see RootPaneContainer#setContentPane 1033 */ 1034 @BeanProperty(bound = false, hidden = true, description 1035 = "The client area of the dialog where child components are normally inserted.") 1036 public void setContentPane(Container contentPane) { 1037 getRootPane().setContentPane(contentPane); 1038 } 1039 1040 /** 1041 * Returns the {@code layeredPane} object for this dialog. 1042 * 1043 * @return the {@code layeredPane} property 1044 * 1045 * @see #setLayeredPane 1046 * @see RootPaneContainer#getLayeredPane 1047 */ 1048 public JLayeredPane getLayeredPane() { 1049 return getRootPane().getLayeredPane(); 1050 } 1051 1052 /** 1053 * Sets the {@code layeredPane} property. 1054 * This method is called by the constructor. 1055 * 1056 * @param layeredPane the new {@code layeredPane} property 1057 * 1058 * @throws java.awt.IllegalComponentStateException (a runtime 1059 * exception) if the layered pane parameter is null 1060 * @see #getLayeredPane 1061 * @see RootPaneContainer#setLayeredPane 1062 */ 1063 @BeanProperty(bound = false, hidden = true, description 1064 = "The pane which holds the various dialog layers.") 1065 public void setLayeredPane(JLayeredPane layeredPane) { 1066 getRootPane().setLayeredPane(layeredPane); 1067 } 1068 1069 /** 1070 * Returns the {@code glassPane} object for this dialog. 1071 * 1072 * @return the {@code glassPane} property 1073 * 1074 * @see #setGlassPane 1075 * @see RootPaneContainer#getGlassPane 1076 */ 1077 public Component getGlassPane() { 1078 return getRootPane().getGlassPane(); 1079 } 1080 1081 /** 1082 * Sets the {@code glassPane} property. 1083 * This method is called by the constructor. 1084 * 1085 * @param glassPane the {@code glassPane} object for this dialog 1086 * @see #getGlassPane 1087 * @see RootPaneContainer#setGlassPane 1088 */ 1089 @BeanProperty(bound = false, hidden = true, description 1090 = "A transparent pane used for menu rendering.") 1091 public void setGlassPane(Component glassPane) { 1092 getRootPane().setGlassPane(glassPane); 1093 } 1094 1095 /** 1096 * {@inheritDoc} 1097 * 1098 * @since 1.6 1099 */ 1100 @BeanProperty(bound = false) 1101 public Graphics getGraphics() { 1102 JComponent.getGraphicsInvoked(this); 1103 return super.getGraphics(); 1104 } 1105 1106 /** 1107 * Repaints the specified rectangle of this component within 1108 * {@code time} milliseconds. Refer to {@code RepaintManager} 1109 * for details on how the repaint is handled. 1110 * 1111 * @param time maximum time in milliseconds before update 1112 * @param x the <i>x</i> coordinate 1113 * @param y the <i>y</i> coordinate 1114 * @param width the width 1115 * @param height the height 1116 * @see RepaintManager 1117 * @since 1.6 1118 */ 1119 public void repaint(long time, int x, int y, int width, int height) { 1120 if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) { |