The Box class can create several kinds
of invisible components
that affect layout:
glue, struts, and rigid areas.
If all the components your Box contains
have a fixed size,
you might want to use a glue component
(returned by createGlue)
to control the components' positions.
If you need a fixed amount of space between two components,
try using a strut
(createHorizontalStrut or createVerticalStrut).
If you need an invisible component
that always takes up the same amount of space,
get it by invoking createRigidArea.
If you are implementing a BoxLayout you
can find further information and examples in
How to Use BoxLayout,
a section in The Java Tutorial.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
BoxLayout
| Modifier and Type | Class and Description |
|---|---|
| protected class | Box.
This class implements accessibility support for the
|
| public static class | Box.
An implementation of a lightweight component that participates in layout but has no view. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static Component | Returns: the componentCreates an invisible "glue" component that can be useful in a Box whose visible components have a maximum width (for a horizontal box) or height (for a vertical box). |
| public static Box | |
| public static Component | |
| public static Component | Returns: the componentthe width of the invisible component, in pixels >= 0 width)Creates an invisible, fixed-width component. |
| public static Component | Returns: the componentthe dimensions of the invisible component d)Creates an invisible component that's always the specified size. |
| public static Box | |
| public static Component | |
| public static Component | Returns: the componentthe height of the invisible component, in pixels >= 0 height)Creates an invisible, fixed-height component. |
| public AccessibleContext | Returns: an AccessibleBox that serves as the AccessibleContext of this BoxOverrides java. Implements javax. Gets the AccessibleContext associated with this Box. |
| protected void | paintComponent(Graphics
the g)Graphics to paint toOverrides javax. Paints this |
| public void | setLayout(LayoutManager
the layout manager to use l)Overrides java. Throws an AWTError, since a Box can use only a BoxLayout. |
| Box | back to summary |
|---|---|
| public Box(int axis) Creates a
| |
| createGlue | back to summary |
|---|---|
| public static Component createGlue() Creates an invisible "glue" component that can be useful in a Box whose visible components have a maximum width (for a horizontal box) or height (for a vertical box). You can think of the glue component as being a gooey substance that expands as much as necessary to fill the space between its neighboring components. For example, suppose you have a horizontal box that contains two fixed-size components. If the box gets extra space, the fixed-size components won't become larger, so where does the extra space go? Without glue, the extra space goes to the right of the second component. If you put glue between the fixed-size components, then the extra space goes there. If you put glue before the first fixed-size component, the extra space goes there, and the fixed-size components are shoved against the right edge of the box. If you put glue before the first fixed-size component and after the second fixed-size component, the fixed-size components are centered in the box.
To use glue,
call
| |
| createHorizontalBox | back to summary |
|---|---|
| public static Box createHorizontalBox() Creates a Box lineBox = new Box(BoxLayout.LINE_AXIS);
| |
| createHorizontalGlue | back to summary |
|---|---|
| public static Component createHorizontalGlue() Creates a horizontal glue component.
| |
| createHorizontalStrut | back to summary |
|---|---|
| public static Component createHorizontalStrut(int width) Creates an invisible, fixed-width component. In a horizontal box, you typically use this method to force a certain amount of space between two components. In a vertical box, you might use this method to force the box to be at least the specified width. The invisible component has no height unless excess space is available, in which case it takes its share of available space, just like any other component that has no maximum height.
| |
| createRigidArea | back to summary |
|---|---|
| public static Component createRigidArea(Dimension d) Creates an invisible component that's always the specified size.
| |
| createVerticalBox | back to summary |
|---|---|
| public static Box createVerticalBox() Creates a Box lineBox = new Box(BoxLayout.PAGE_AXIS);
| |
| createVerticalGlue | back to summary |
|---|---|
| public static Component createVerticalGlue() Creates a vertical glue component.
| |
| createVerticalStrut | back to summary |
|---|---|
| public static Component createVerticalStrut(int height) Creates an invisible, fixed-height component. In a vertical box, you typically use this method to force a certain amount of space between two components. In a horizontal box, you might use this method to force the box to be at least the specified height. The invisible component has no width unless excess space is available, in which case it takes its share of available space, just like any other component that has no maximum width.
| |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the AccessibleContext associated with this Box. For boxes, the AccessibleContext takes the form of an AccessibleBox. A new AccessibleAWTBox instance is created if necessary.
| |
| paintComponent | back to summary |
|---|---|
| protected void paintComponent(Graphics g) Overrides javax. Paints this
| |
| setLayout | back to summary |
|---|---|
| public void setLayout(LayoutManager l) Overrides java. Throws an AWTError, since a Box can use only a BoxLayout.
| |
Box class.
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the object (AccessibleRole.FILLER)Overrides java. Gets the role of this object. |
| AccessibleBox | back to summary |
|---|---|
| protected AccessibleBox() Constructs an | |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides java. Gets the role of this object.
| |
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Class and Description |
|---|---|
| protected class | Box.
This class implements accessibility support for the
|
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | changeShape(Dimension
Value to return for getMinimumSize min, Dimension Value to return for getPreferredSize pref, Dimension Value to return for getMaximumSize max)Change the size requests for this shape. |
| public AccessibleContext | Returns: an AccessibleBoxFiller that serves as the AccessibleContext of this Box.Filler.Overrides java. Implements javax. Gets the AccessibleContext associated with this Box.Filler. |
| protected void | paintComponent(Graphics
the g)Graphics to paint toOverrides javax. Paints this |
| Filler | back to summary |
|---|---|
| public Filler(Dimension min, Dimension pref, Dimension max) Constructor to create shape with the given size ranges.
| |
| changeShape | back to summary |
|---|---|
| public void changeShape(Dimension min, Dimension pref, Dimension max) Change the size requests for this shape. An invalidate() is propagated upward as a result so that layout will eventually happen with using the new sizes. | |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the AccessibleContext associated with this Box.Filler. For box fillers, the AccessibleContext takes the form of an AccessibleBoxFiller. A new AccessibleAWTBoxFiller instance is created if necessary.
| |
| paintComponent | back to summary |
|---|---|
| protected void paintComponent(Graphics g) Overrides javax. Paints this
| |
Box.Filler class.
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the object (AccessibleRole.FILLER)Overrides java. Gets the role of this object. |
| AccessibleBoxFiller | back to summary |
|---|---|
| protected AccessibleBoxFiller() Constructs an | |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides java. Gets the role of this object.
| |