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
29 import javax.swing.plaf.*;
30 import javax.accessibility.*;
31
32 import java.io.Serializable;
33 import java.io.ObjectOutputStream;
34 import java.io.ObjectInputStream;
35 import java.io.IOException;
36
37
38 /**
39 * <code>JPanel</code> is a generic lightweight container.
40 * For examples and task-oriented documentation for JPanel, see
41 * <a
42 href="http://docs.oracle.com/javase/tutorial/uiswing/components/panel.html">How to Use Panels</a>,
43 * a section in <em>The Java Tutorial</em>.
44 * <p>
45 * <strong>Warning:</strong> Swing is not thread safe. For more
46 * information see <a
47 * href="package-summary.html#threading">Swing's Threading
48 * Policy</a>.
49 * <p>
50 * <strong>Warning:</strong>
51 * Serialized objects of this class will not be compatible with
52 * future Swing releases. The current serialization support is
53 * appropriate for short term storage or RMI between applications running
54 * the same version of Swing. As of 1.4, support for long term storage
55 * of all JavaBeans™
56 * has been added to the <code>java.beans</code> package.
57 * Please see {@link java.beans.XMLEncoder}.
58 *
59 * @beaninfo
60 * description: A generic lightweight container.
61 *
62 * @author Arnaud Weber
63 * @author Steve Wilson
64 * @since 1.2
65 */
66 @SuppressWarnings("serial") // Same-version serialization only
67 public class JPanel extends JComponent implements Accessible
68 {
69 /**
70 * @see #getUIClassID
71 * @see #readObject
72 */
73 private static final String uiClassID = "PanelUI";
74
75 /**
76 * Creates a new JPanel with the specified layout manager and buffering
77 * strategy.
78 *
79 * @param layout the LayoutManager to use
80 * @param isDoubleBuffered a boolean, true for double-buffering, which
81 * uses additional memory space to achieve fast, flicker-free
82 * updates
83 */
84 public JPanel(LayoutManager layout, boolean isDoubleBuffered) {
85 setLayout(layout);
128 setUI((PanelUI)UIManager.getUI(this));
129 }
130
131 /**
132 * Returns the look and feel (L&amp;F) object that renders this component.
133 *
134 * @return the PanelUI object that renders this component
135 * @since 1.4
136 */
137 public PanelUI getUI() {
138 return (PanelUI)ui;
139 }
140
141
142 /**
143 * Sets the look and feel (L&F) object that renders this component.
144 *
145 * @param ui the PanelUI L&F object
146 * @see UIDefaults#getUI
147 * @since 1.4
148 * @beaninfo
149 * bound: true
150 * hidden: true
151 * attribute: visualUpdate true
152 * description: The UI object that implements the Component's LookAndFeel.
153 */
154 public void setUI(PanelUI ui) {
155 super.setUI(ui);
156 }
157
158 /**
159 * Returns a string that specifies the name of the L&F class
160 * that renders this component.
161 *
162 * @return "PanelUI"
163 * @see JComponent#getUIClassID
164 * @see UIDefaults#getUI
165 * @beaninfo
166 * expert: true
167 * description: A string that specifies the name of the L&F class.
168 */
169 public String getUIClassID() {
170 return uiClassID;
171 }
172
173
174 /**
175 * See readObject() and writeObject() in JComponent for more
176 * information about serialization in Swing.
177 */
178 private void writeObject(ObjectOutputStream s) throws IOException {
179 s.defaultWriteObject();
180 if (getUIClassID().equals(uiClassID)) {
181 byte count = JComponent.getWriteObjCounter(this);
182 JComponent.setWriteObjCounter(this, --count);
183 if (count == 0 && ui != null) {
184 ui.installUI(this);
185 }
186 }
187 }
188
196 *
197 * @return a string representation of this JPanel.
198 */
199 protected String paramString() {
200 return super.paramString();
201 }
202
203 /////////////////
204 // Accessibility support
205 ////////////////
206
207 /**
208 * Gets the AccessibleContext associated with this JPanel.
209 * For JPanels, the AccessibleContext takes the form of an
210 * AccessibleJPanel.
211 * A new AccessibleJPanel instance is created if necessary.
212 *
213 * @return an AccessibleJPanel that serves as the
214 * AccessibleContext of this JPanel
215 */
216 public AccessibleContext getAccessibleContext() {
217 if (accessibleContext == null) {
218 accessibleContext = new AccessibleJPanel();
219 }
220 return accessibleContext;
221 }
222
223 /**
224 * This class implements accessibility support for the
225 * <code>JPanel</code> class. It provides an implementation of the
226 * Java Accessibility API appropriate to panel user-interface
227 * elements.
228 * <p>
229 * <strong>Warning:</strong>
230 * Serialized objects of this class will not be compatible with
231 * future Swing releases. The current serialization support is
232 * appropriate for short term storage or RMI between applications running
233 * the same version of Swing. As of 1.4, support for long term storage
234 * of all JavaBeans™
235 * has been added to the <code>java.beans</code> package.
|
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.beans.JavaBean;
29 import java.beans.BeanProperty;
30
31 import javax.swing.plaf.*;
32 import javax.accessibility.*;
33
34 import java.io.ObjectOutputStream;
35 import java.io.IOException;
36
37
38 /**
39 * <code>JPanel</code> is a generic lightweight container.
40 * For examples and task-oriented documentation for JPanel, see
41 * <a
42 href="http://docs.oracle.com/javase/tutorial/uiswing/components/panel.html">How to Use Panels</a>,
43 * a section in <em>The Java Tutorial</em>.
44 * <p>
45 * <strong>Warning:</strong> Swing is not thread safe. For more
46 * information see <a
47 * href="package-summary.html#threading">Swing's Threading
48 * Policy</a>.
49 * <p>
50 * <strong>Warning:</strong>
51 * Serialized objects of this class will not be compatible with
52 * future Swing releases. The current serialization support is
53 * appropriate for short term storage or RMI between applications running
54 * the same version of Swing. As of 1.4, support for long term storage
55 * of all JavaBeans™
56 * has been added to the <code>java.beans</code> package.
57 * Please see {@link java.beans.XMLEncoder}.
58 *
59 * @author Arnaud Weber
60 * @author Steve Wilson
61 * @since 1.2
62 */
63 @JavaBean(defaultProperty = "UI", description = "A generic lightweight container.")
64 @SuppressWarnings("serial") // Same-version serialization only
65 public class JPanel extends JComponent implements Accessible
66 {
67 /**
68 * @see #getUIClassID
69 * @see #readObject
70 */
71 private static final String uiClassID = "PanelUI";
72
73 /**
74 * Creates a new JPanel with the specified layout manager and buffering
75 * strategy.
76 *
77 * @param layout the LayoutManager to use
78 * @param isDoubleBuffered a boolean, true for double-buffering, which
79 * uses additional memory space to achieve fast, flicker-free
80 * updates
81 */
82 public JPanel(LayoutManager layout, boolean isDoubleBuffered) {
83 setLayout(layout);
126 setUI((PanelUI)UIManager.getUI(this));
127 }
128
129 /**
130 * Returns the look and feel (L&amp;F) object that renders this component.
131 *
132 * @return the PanelUI object that renders this component
133 * @since 1.4
134 */
135 public PanelUI getUI() {
136 return (PanelUI)ui;
137 }
138
139
140 /**
141 * Sets the look and feel (L&F) object that renders this component.
142 *
143 * @param ui the PanelUI L&F object
144 * @see UIDefaults#getUI
145 * @since 1.4
146 */
147 @BeanProperty(hidden = true, visualUpdate = true, description
148 = "The UI object that implements the Component's LookAndFeel.")
149 public void setUI(PanelUI ui) {
150 super.setUI(ui);
151 }
152
153 /**
154 * Returns a string that specifies the name of the L&F class
155 * that renders this component.
156 *
157 * @return "PanelUI"
158 * @see JComponent#getUIClassID
159 * @see UIDefaults#getUI
160 */
161 @BeanProperty(bound = false, expert = true, description
162 = "A string that specifies the name of the L&F class.")
163 public String getUIClassID() {
164 return uiClassID;
165 }
166
167
168 /**
169 * See readObject() and writeObject() in JComponent for more
170 * information about serialization in Swing.
171 */
172 private void writeObject(ObjectOutputStream s) throws IOException {
173 s.defaultWriteObject();
174 if (getUIClassID().equals(uiClassID)) {
175 byte count = JComponent.getWriteObjCounter(this);
176 JComponent.setWriteObjCounter(this, --count);
177 if (count == 0 && ui != null) {
178 ui.installUI(this);
179 }
180 }
181 }
182
190 *
191 * @return a string representation of this JPanel.
192 */
193 protected String paramString() {
194 return super.paramString();
195 }
196
197 /////////////////
198 // Accessibility support
199 ////////////////
200
201 /**
202 * Gets the AccessibleContext associated with this JPanel.
203 * For JPanels, the AccessibleContext takes the form of an
204 * AccessibleJPanel.
205 * A new AccessibleJPanel instance is created if necessary.
206 *
207 * @return an AccessibleJPanel that serves as the
208 * AccessibleContext of this JPanel
209 */
210 @BeanProperty(bound = false)
211 public AccessibleContext getAccessibleContext() {
212 if (accessibleContext == null) {
213 accessibleContext = new AccessibleJPanel();
214 }
215 return accessibleContext;
216 }
217
218 /**
219 * This class implements accessibility support for the
220 * <code>JPanel</code> class. It provides an implementation of the
221 * Java Accessibility API appropriate to panel user-interface
222 * elements.
223 * <p>
224 * <strong>Warning:</strong>
225 * Serialized objects of this class will not be compatible with
226 * future Swing releases. The current serialization support is
227 * appropriate for short term storage or RMI between applications running
228 * the same version of Swing. As of 1.4, support for long term storage
229 * of all JavaBeans™
230 * has been added to the <code>java.beans</code> package.
|