Package com.jidesoft.swing
Class JideBoxLayout
java.lang.Object
com.jidesoft.swing.JideBoxLayout
- All Implemented Interfaces:
LayoutManager
,LayoutManager2
,Serializable
- Direct Known Subclasses:
JideSplitPaneLayout
JideBoxLayout is very similar to BoxLayout in the way that all components are arranged either from left to right or
from top to bottom. Different \ from BoxLayout, there are three possible constraints when adding component to this
layout - FIX, FLEXIBLE and VARY.
- FIX: use the preferred size of the component and size is fixed
- FLEXIBLE: respect the preferred size of the component but size can be changed.
- VARY: ignore preferred size. Its size is calculated based how much area left.
JideSplitPane
.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Axis, 0 for horizontal, or 1 for vertical.protected int[]
protected Container
static final String
For FIX component, the width (or height if vertical) is and will always be the preferred width.static final String
FLEXIBLE components try to keep the preferred width.static final int
Specifies that components should be laid out in the direction of a line of text as determined by the target container'sComponentOrientation
property.static final int
Specifies that components should be laid out in the direction that lines flow across a page as determined by the target container'sComponentOrientation
property.static final String
For VARY component, the width will always be whatever width left.static final int
Specifies that components should be laid out left to right.static final int
Specifies that components should be laid out top to bottom. -
Constructor Summary
ConstructorsConstructorDescriptionJideBoxLayout
(Container target) Creates a layout manager that will lay out components along the given axis.JideBoxLayout
(Container target, int axis) JideBoxLayout
(Container target, int axis, int gap) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLayoutComponent
(Component comp, Object constraints) Adds the specified component to the layout, using the specified constraint object.void
addLayoutComponent
(String name, Component component) If the layout manager uses a per-component string, adds the componentcomp
to the layout, associating it with the string specified byname
.protected boolean
calculateComponentSizes
(int availableSize, int startIndex, int endIndex) protected boolean
protected int
getAvailableSize
(Dimension containerSize, Insets insets) Returns the available width based on the container size and Insets.int
getAxis()
Gets the axis.Gets the map of constraints.int
getGap()
Gets the gap between each component.protected int
getInitialLocation
(Insets insets) Returns the left inset, unless the Insets are null in which case 0 is returned.float
getLayoutAlignmentX
(Container target) Returns the alignment along the x axis.float
getLayoutAlignmentY
(Container target) Returns the alignment along the y axis.protected Dimension
getPreferredSizeOf
(Component comp, int atIndex) protected int
Returns the width of the passed in Components preferred size.protected int
Returns the width of the passed in component.void
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.boolean
Checks if the alwaysLayout flag is true.boolean
Checks of the layout should be reset wheninvalidateLayout(java.awt.Container)
is called.void
layoutContainer
(Container container) Lays out the specified container.maximumLayoutSize
(Container target) Returns the maximum layout size, which is Integer.MAX_VALUE in both directions.minimumLayoutSize
(Container container) Returns the minimum size needed to contain the children.preferredLayoutSize
(Container container) Returns the preferred size needed to contain the children.void
Removes the specified component from the layout.protected static int
resolveAxis
(int axis, ComponentOrientation o) Given one of the 4 axis values, resolve it to an absolute axis.void
setAlwaysLayout
(boolean alwaysLayout) Sets the alwaysLayout flag.void
setAxis
(int axis) Sets the axis.protected void
setComponentToSize
(Component c, int size, int location, Insets insets, Dimension containerSize) Sets the width of the component c to be size, placing its x location at location, y to the insets.top and height to the containersize.height less the top and bottom insets.void
setGap
(int gap) Sets the gap between each component.void
setResetWhenInvalidate
(boolean resetWhenInvalidate) Sets the flag if the layout should be reset wheninvalidateLayout(java.awt.Container)
is called.
-
Field Details
-
_axis
protected int _axisAxis, 0 for horizontal, or 1 for vertical. -
_target
-
_componentSizes
protected int[] _componentSizes -
FIX
For FIX component, the width (or height if vertical) is and will always be the preferred width.- See Also:
-
FLEXIBLE
FLEXIBLE components try to keep the preferred width. If there isn't enough space, all FLEXIBLE components will shrink proportionally.- See Also:
-
VARY
For VARY component, the width will always be whatever width left. You can allow add multiple FIX or FLEXIBLE components but only one VARY component is allowed.- See Also:
-
X_AXIS
public static final int X_AXISSpecifies that components should be laid out left to right.- See Also:
-
Y_AXIS
public static final int Y_AXISSpecifies that components should be laid out top to bottom.- See Also:
-
LINE_AXIS
public static final int LINE_AXISSpecifies that components should be laid out in the direction of a line of text as determined by the target container'sComponentOrientation
property.- See Also:
-
PAGE_AXIS
public static final int PAGE_AXISSpecifies that components should be laid out in the direction that lines flow across a page as determined by the target container'sComponentOrientation
property.- See Also:
-
-
Constructor Details
-
JideBoxLayout
Creates a layout manager that will lay out components along the given axis.- Parameters:
target
- the container that needs to be laid out- Throws:
AWTError
- if the value ofaxis
is invalid
-
JideBoxLayout
- Parameters:
target
- the container that needs to be laid outaxis
- the axis to lay out components along. Can be one of:JideBoxLayout.X_AXIS
,JideBoxLayout.Y_AXIS
,JideBoxLayout.LINE_AXIS
orJideBoxLayout.PAGE_AXIS
-
JideBoxLayout
- Parameters:
target
- the container that needs to be laid outaxis
- the axis to lay out components along. Can be one of:JideBoxLayout.X_AXIS
,JideBoxLayout.Y_AXIS
,JideBoxLayout.LINE_AXIS
orJideBoxLayout.PAGE_AXIS
gap
- the gap
-
-
Method Details
-
layoutContainer
Lays out the specified container.- Specified by:
layoutContainer
in interfaceLayoutManager
- Parameters:
container
- the container to be laid out
-
calculateComponentSizes
protected boolean calculateComponentSizes(int availableSize, int startIndex, int endIndex) -
addLayoutComponent
If the layout manager uses a per-component string, adds the componentcomp
to the layout, associating it with the string specified byname
.- Specified by:
addLayoutComponent
in interfaceLayoutManager
- Parameters:
name
- the string to be associated with the componentcomponent
- the component to be added
-
minimumLayoutSize
Returns the minimum size needed to contain the children. The width is the sum of all the children min widths and the height is the largest of the children minimum heights.- Specified by:
minimumLayoutSize
in interfaceLayoutManager
-
preferredLayoutSize
Returns the preferred size needed to contain the children. The width is the sum of all the children preferred widths and the height is the largest of the children preferred heights.- Specified by:
preferredLayoutSize
in interfaceLayoutManager
-
removeLayoutComponent
Removes the specified component from the layout.- Specified by:
removeLayoutComponent
in interfaceLayoutManager
- Parameters:
comp
- the component to be removed
-
addLayoutComponent
Adds the specified component to the layout, using the specified constraint object.- Specified by:
addLayoutComponent
in interfaceLayoutManager2
- Parameters:
comp
- the component to be addedconstraints
- where/how the component is added to the layout.
-
getLayoutAlignmentX
Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.- Specified by:
getLayoutAlignmentX
in interfaceLayoutManager2
-
getLayoutAlignmentY
Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.- Specified by:
getLayoutAlignmentY
in interfaceLayoutManager2
-
invalidateLayout
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.- Specified by:
invalidateLayout
in interfaceLayoutManager2
-
componentCountChanged
-
maximumLayoutSize
Returns the maximum layout size, which is Integer.MAX_VALUE in both directions.- Specified by:
maximumLayoutSize
in interfaceLayoutManager2
-
getPreferredSizeOfComponent
Returns the width of the passed in Components preferred size.- Parameters:
c
- the component- Returns:
- the preferred size of the component.
-
getSizeOfComponent
Returns the width of the passed in component.- Parameters:
c
- the component- Returns:
- the size of the component.
-
getAvailableSize
Returns the available width based on the container size and Insets.- Parameters:
containerSize
- the size of the containerinsets
- the insets- Returns:
- the available size.
-
getInitialLocation
Returns the left inset, unless the Insets are null in which case 0 is returned.- Parameters:
insets
- the insets- Returns:
- the initial location.
-
setComponentToSize
protected void setComponentToSize(Component c, int size, int location, Insets insets, Dimension containerSize) Sets the width of the component c to be size, placing its x location at location, y to the insets.top and height to the containersize.height less the top and bottom insets.- Parameters:
c
- the componentsize
- the size of the componentlocation
- the location of the componentinsets
- the insets of the componentcontainerSize
- the size of the container
-
getConstraintMap
Gets the map of constraints.- Returns:
- the map of constraints
-
resolveAxis
Given one of the 4 axis values, resolve it to an absolute axis. The relative axis values, PAGE_AXIS and LINE_AXIS are converted to their absolute counterpart given the target's ComponentOrientation value. The absolute axes, X_AXIS and Y_AXIS are returned unmodified.- Parameters:
axis
- the axis to resolveo
- the ComponentOrientation to resolve against- Returns:
- the resolved axis
-
getGap
public int getGap()Gets the gap between each component.- Returns:
- the gap between each component.
-
setGap
public void setGap(int gap) Sets the gap between each component. Make sure you cal doLayout() after you change the gap.- Parameters:
gap
- the gap
-
getPreferredSizeOf
-
isResetWhenInvalidate
public boolean isResetWhenInvalidate()Checks of the layout should be reset wheninvalidateLayout(java.awt.Container)
is called.- Returns:
- true or false.
-
setResetWhenInvalidate
public void setResetWhenInvalidate(boolean resetWhenInvalidate) Sets the flag if the layout should be reset wheninvalidateLayout(java.awt.Container)
is called.- Parameters:
resetWhenInvalidate
- the flag
-
getAxis
public int getAxis()Gets the axis.- Returns:
- the axis.
-
setAxis
public void setAxis(int axis) Sets the axis. After changing the axis, you need to call doLayout method on the container which has this layout.- Parameters:
axis
- the new axis.
-
isAlwaysLayout
public boolean isAlwaysLayout()Checks if the alwaysLayout flag is true. If true, the layout manager will layout the components even there is no way to satisfy the minimum size requirements from all FIXED components. By default, it is true.- Returns:
- true or false.
-
setAlwaysLayout
public void setAlwaysLayout(boolean alwaysLayout) Sets the alwaysLayout flag.- Parameters:
alwaysLayout
- true to always layout components even there is no way to satisfy the minimum size requirements from all FIXED components.
-