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 81 * uses additional memory space to achieve fast, flicker-free 82 * updates 83 */ 84 public JPanel(LayoutManager layout, boolean isDoubleBuffered) { 85 setLayout(layout); 86 setDoubleBuffered(isDoubleBuffered); 87 setUIProperty("opaque", Boolean.TRUE); 88 updateUI(); 89 } 90 91 /** 92 * Create a new buffered JPanel with the specified layout manager 93 * 94 * @param layout the LayoutManager to use 95 */ 96 public JPanel(LayoutManager layout) { 97 this(layout, true); 98 } 99 100 /** 101 * Creates a new <code>JPanel</code> with <code>FlowLayout</code> 102 * and the specified buffering strategy. 103 * If <code>isDoubleBuffered</code> is true, the <code>JPanel</code> 104 * will use a double buffer. 105 * 106 * @param isDoubleBuffered a boolean, true for double-buffering, which 107 * uses additional memory space to achieve fast, flicker-free 108 * updates 109 */ 110 public JPanel(boolean isDoubleBuffered) { 111 this(new FlowLayout(), isDoubleBuffered); 112 } 113 114 /** 115 * Creates a new <code>JPanel</code> with a double buffer 116 * and a flow layout. 117 */ 118 public JPanel() { 119 this(true); 120 } 121 122 /** 123 * Resets the UI property with a value from the current look and feel. 124 * 125 * @see JComponent#updateUI 126 */ 127 public void updateUI() { 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 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 189 190 /** 191 * Returns a string representation of this JPanel. This method 192 * is intended to be used only for debugging purposes, and the 193 * content and format of the returned string may vary between 194 * implementations. The returned string may be empty but may not 195 * be <code>null</code>. 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. 236 * Please see {@link java.beans.XMLEncoder}. 237 */ 238 @SuppressWarnings("serial") // Same-version serialization only 239 protected class AccessibleJPanel extends AccessibleJComponent { 240 241 /** 242 * Get the role of this object. 243 * 244 * @return an instance of AccessibleRole describing the role of the 245 * object 246 */ 247 public AccessibleRole getAccessibleRole() { 248 return AccessibleRole.PANEL; 249 } 250 } 251 } | 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} 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} 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 81 * uses additional memory space to achieve fast, flicker-free 82 * updates 83 */ 84 public JPanel(LayoutManager layout, boolean isDoubleBuffered) { 85 setLayout(layout); 86 setDoubleBuffered(isDoubleBuffered); 87 setUIProperty("opaque", Boolean.TRUE); 88 updateUI(); 89 } 90 91 /** 92 * Create a new buffered JPanel with the specified layout manager 93 * 94 * @param layout the LayoutManager to use 95 */ 96 public JPanel(LayoutManager layout) { 97 this(layout, true); 98 } 99 100 /** 101 * Creates a new {@code JPanel} with {@code FlowLayout} 102 * and the specified buffering strategy. 103 * If {@code isDoubleBuffered} is true, the {@code JPanel} 104 * will use a double buffer. 105 * 106 * @param isDoubleBuffered a boolean, true for double-buffering, which 107 * uses additional memory space to achieve fast, flicker-free 108 * updates 109 */ 110 public JPanel(boolean isDoubleBuffered) { 111 this(new FlowLayout(), isDoubleBuffered); 112 } 113 114 /** 115 * Creates a new {@code JPanel} with a double buffer 116 * and a flow layout. 117 */ 118 public JPanel() { 119 this(true); 120 } 121 122 /** 123 * Resets the UI property with a value from the current look and feel. 124 * 125 * @see JComponent#updateUI 126 */ 127 public void updateUI() { 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 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 189 190 /** 191 * Returns a string representation of this JPanel. This method 192 * is intended to be used only for debugging purposes, and the 193 * content and format of the returned string may vary between 194 * implementations. The returned string may be empty but may not 195 * be {@code null}. 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} 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} package. 236 * Please see {@link java.beans.XMLEncoder}. 237 */ 238 @SuppressWarnings("serial") // Same-version serialization only 239 protected class AccessibleJPanel extends AccessibleJComponent { 240 241 /** 242 * Get the role of this object. 243 * 244 * @return an instance of AccessibleRole describing the role of the 245 * object 246 */ 247 public AccessibleRole getAccessibleRole() { 248 return AccessibleRole.PANEL; 249 } 250 } 251 } |