src/java.desktop/share/classes/javax/swing/Box.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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 
  26 
  27 package javax.swing;
  28 
  29 import java.awt.*;
  30 import java.awt.event.*;

  31 import java.beans.ConstructorProperties;
  32 import java.util.Locale;
  33 import java.io.Serializable;
  34 import javax.accessibility.*;
  35 
  36 /**
  37  * A lightweight container
  38  * that uses a BoxLayout object as its layout manager.
  39  * Box provides several class methods
  40  * that are useful for containers using BoxLayout --
  41  * even non-Box containers.
  42  *
  43  * <p>
  44  * The <code>Box</code> class can create several kinds
  45  * of invisible components
  46  * that affect layout:
  47  * glue, struts, and rigid areas.
  48  * If all the components your <code>Box</code> contains
  49  * have a fixed size,
  50  * you might want to use a glue component
  51  * (returned by <code>createGlue</code>)
  52  * to control the components' positions.
  53  * If you need a fixed amount of space between two components,


  60  * If you are implementing a <code>BoxLayout</code> you
  61  * can find further information and examples in
  62  * <a
  63  href="http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html">How to Use BoxLayout</a>,
  64  * a section in <em>The Java Tutorial.</em>
  65  * <p>
  66  * <strong>Warning:</strong>
  67  * Serialized objects of this class will not be compatible with
  68  * future Swing releases. The current serialization support is
  69  * appropriate for short term storage or RMI between applications running
  70  * the same version of Swing.  As of 1.4, support for long term storage
  71  * of all JavaBeans&trade;
  72  * has been added to the <code>java.beans</code> package.
  73  * Please see {@link java.beans.XMLEncoder}.
  74  *
  75  * @see BoxLayout
  76  *
  77  * @author  Timothy Prinzing
  78  * @since 1.2
  79  */

  80 @SuppressWarnings("serial")
  81 public class Box extends JComponent implements Accessible {
  82 
  83     /**
  84      * Creates a <code>Box</code> that displays its components
  85      * along the specified axis.
  86      *
  87      * @param axis  can be {@link BoxLayout#X_AXIS},
  88      *              {@link BoxLayout#Y_AXIS},
  89      *              {@link BoxLayout#LINE_AXIS} or
  90      *              {@link BoxLayout#PAGE_AXIS}.
  91      * @throws AWTError if the <code>axis</code> is invalid
  92      * @see #createHorizontalBox
  93      * @see #createVerticalBox
  94      */
  95     public Box(int axis) {
  96         super();
  97         super.setLayout(new BoxLayout(this, axis));
  98     }
  99 


 396              */
 397             public AccessibleRole getAccessibleRole() {
 398                 return AccessibleRole.FILLER;
 399             }
 400         }
 401     }
 402 
 403 /////////////////
 404 // Accessibility support for Box
 405 ////////////////
 406 
 407     /**
 408      * Gets the AccessibleContext associated with this Box.
 409      * For boxes, the AccessibleContext takes the form of an
 410      * AccessibleBox.
 411      * A new AccessibleAWTBox instance is created if necessary.
 412      *
 413      * @return an AccessibleBox that serves as the
 414      *         AccessibleContext of this Box
 415      */

 416     public AccessibleContext getAccessibleContext() {
 417         if (accessibleContext == null) {
 418             accessibleContext = new AccessibleBox();
 419         }
 420         return accessibleContext;
 421     }
 422 
 423     /**
 424      * This class implements accessibility support for the
 425      * <code>Box</code> class.
 426      */
 427     @SuppressWarnings("serial")
 428     protected class AccessibleBox extends AccessibleAWTContainer {
 429         // AccessibleContext methods
 430         //
 431         /**
 432          * Gets the role of this object.
 433          *
 434          * @return an instance of AccessibleRole describing the role of the
 435          *   object (AccessibleRole.FILLER)
   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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 import java.beans.ConstructorProperties;


  31 import javax.accessibility.*;
  32 
  33 /**
  34  * A lightweight container
  35  * that uses a BoxLayout object as its layout manager.
  36  * Box provides several class methods
  37  * that are useful for containers using BoxLayout --
  38  * even non-Box containers.
  39  *
  40  * <p>
  41  * The <code>Box</code> class can create several kinds
  42  * of invisible components
  43  * that affect layout:
  44  * glue, struts, and rigid areas.
  45  * If all the components your <code>Box</code> contains
  46  * have a fixed size,
  47  * you might want to use a glue component
  48  * (returned by <code>createGlue</code>)
  49  * to control the components' positions.
  50  * If you need a fixed amount of space between two components,


  57  * If you are implementing a <code>BoxLayout</code> you
  58  * can find further information and examples in
  59  * <a
  60  href="http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html">How to Use BoxLayout</a>,
  61  * a section in <em>The Java Tutorial.</em>
  62  * <p>
  63  * <strong>Warning:</strong>
  64  * Serialized objects of this class will not be compatible with
  65  * future Swing releases. The current serialization support is
  66  * appropriate for short term storage or RMI between applications running
  67  * the same version of Swing.  As of 1.4, support for long term storage
  68  * of all JavaBeans&trade;
  69  * has been added to the <code>java.beans</code> package.
  70  * Please see {@link java.beans.XMLEncoder}.
  71  *
  72  * @see BoxLayout
  73  *
  74  * @author  Timothy Prinzing
  75  * @since 1.2
  76  */
  77 @JavaBean(defaultProperty = "accessibleContext")
  78 @SuppressWarnings("serial")
  79 public class Box extends JComponent implements Accessible {
  80 
  81     /**
  82      * Creates a <code>Box</code> that displays its components
  83      * along the specified axis.
  84      *
  85      * @param axis  can be {@link BoxLayout#X_AXIS},
  86      *              {@link BoxLayout#Y_AXIS},
  87      *              {@link BoxLayout#LINE_AXIS} or
  88      *              {@link BoxLayout#PAGE_AXIS}.
  89      * @throws AWTError if the <code>axis</code> is invalid
  90      * @see #createHorizontalBox
  91      * @see #createVerticalBox
  92      */
  93     public Box(int axis) {
  94         super();
  95         super.setLayout(new BoxLayout(this, axis));
  96     }
  97 


 394              */
 395             public AccessibleRole getAccessibleRole() {
 396                 return AccessibleRole.FILLER;
 397             }
 398         }
 399     }
 400 
 401 /////////////////
 402 // Accessibility support for Box
 403 ////////////////
 404 
 405     /**
 406      * Gets the AccessibleContext associated with this Box.
 407      * For boxes, the AccessibleContext takes the form of an
 408      * AccessibleBox.
 409      * A new AccessibleAWTBox instance is created if necessary.
 410      *
 411      * @return an AccessibleBox that serves as the
 412      *         AccessibleContext of this Box
 413      */
 414     @BeanProperty(bound = false)
 415     public AccessibleContext getAccessibleContext() {
 416         if (accessibleContext == null) {
 417             accessibleContext = new AccessibleBox();
 418         }
 419         return accessibleContext;
 420     }
 421 
 422     /**
 423      * This class implements accessibility support for the
 424      * <code>Box</code> class.
 425      */
 426     @SuppressWarnings("serial")
 427     protected class AccessibleBox extends AccessibleAWTContainer {
 428         // AccessibleContext methods
 429         //
 430         /**
 431          * Gets the role of this object.
 432          *
 433          * @return an instance of AccessibleRole describing the role of the
 434          *   object (AccessibleRole.FILLER)