Package se.datadosen.component
Class RiverLayout
java.lang.Object
java.awt.FlowLayout
se.datadosen.component.RiverLayout
- All Implemented Interfaces:
LayoutManager
,Serializable
RiverLayout makes it very simple to construct user interfaces as components are laid out similar to how text is added to a word processor (Components flow like a "river". RiverLayout is however much more powerful than FlowLayout: Components added with the add() method generally gets laid out horizontally, but one may add a string before the component being added to specify "constraints" like this: add("br hfill", new JTextField("Your name here"); The code above forces a "line break" and extends the added component horizontally. Without the "hfill" constraint, the component would take on its preferred size.
List of constraints:
- br - Add a line break
- p - Add a paragraph break
- tab - Add a tab stop (handy for constructing forms with labels followed by fields)
- hfill - Extend component horizontally
- vfill - Extent component vertically (only one line allowed per container) //$rh
- left - Align following components to the left (default)
- center - Align following components horizontally centered
- right - Align following components to the right
- vtop - Align following components vertically top aligned
- vcenter - Align following components vertically centered (default)
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class java.awt.FlowLayout
LEADING, TRAILING
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addLayoutComponent
(String name, Component comp) protected void
protected se.datadosen.component.Ruler
Figure out tab stop x-positionsGets the extra insets of all the components in the container.int
getHgap()
Gets the horizontal gap between components.protected Insets
int
getVgap()
Gets the vertical gap between components.void
layoutContainer
(Container target) Lays out the container.minimumLayoutSize
(Container target) Returns the minimum dimensions needed to layout the visible components contained in the specified target container.protected void
moveComponents
(Container target, int x, int y, int width, int height, int rowStart, int rowEnd, boolean ltr, se.datadosen.component.Ruler ruler) Centers the elements in the specified row, if there is any slack.preferredLayoutSize
(Container target) Returns the preferred dimensions for this layout given the visible components in the specified target container.protected void
void
Removes the specified component from the layout.void
setExtraInsets
(Insets newExtraInsets) Set the extra insets of all the components in the container.void
setHgap
(int hgap) Sets the horizontal gap between components.void
setVgap
(int vgap) Sets the vertical gap between components.Methods inherited from class java.awt.FlowLayout
getAlignment, getAlignOnBaseline, setAlignment, setAlignOnBaseline, toString
-
Field Details
-
LINE_BREAK
- See Also:
-
PARAGRAPH_BREAK
- See Also:
-
TAB_STOP
- See Also:
-
HFILL
- See Also:
-
VFILL
- See Also:
-
LEFT
- See Also:
-
RIGHT
- See Also:
-
CENTER
- See Also:
-
VTOP
- See Also:
-
VCENTER
- See Also:
-
VBOTTOM
- See Also:
-
LABEL
- See Also:
-
-
Constructor Details
-
RiverLayout
public RiverLayout() -
RiverLayout
public RiverLayout(int hgap, int vgap)
-
-
Method Details
-
getHgap
public int getHgap()Gets the horizontal gap between components.- Overrides:
getHgap
in classFlowLayout
-
setHgap
public void setHgap(int hgap) Sets the horizontal gap between components.- Overrides:
setHgap
in classFlowLayout
-
getVgap
public int getVgap()Gets the vertical gap between components.- Overrides:
getVgap
in classFlowLayout
-
getExtraInsets
Gets the extra insets of all the components in the container. -
setExtraInsets
Set the extra insets of all the components in the container. -
getInsets
-
setVgap
public void setVgap(int vgap) Sets the vertical gap between components.- Overrides:
setVgap
in classFlowLayout
-
addLayoutComponent
- Specified by:
addLayoutComponent
in interfaceLayoutManager
- Overrides:
addLayoutComponent
in classFlowLayout
- Parameters:
name
- the name of the componentcomp
- the component to be added
-
removeLayoutComponent
Removes the specified component from the layout. Not used by this class.- Specified by:
removeLayoutComponent
in interfaceLayoutManager
- Overrides:
removeLayoutComponent
in classFlowLayout
- Parameters:
comp
- the component to remove- See Also:
-
calcTabs
Figure out tab stop x-positions -
preferredLayoutSize
Returns the preferred dimensions for this layout given the visible components in the specified target container.- Specified by:
preferredLayoutSize
in interfaceLayoutManager
- Overrides:
preferredLayoutSize
in classFlowLayout
- Parameters:
target
- the component which needs to be laid out- Returns:
- the preferred dimensions to lay out the subcomponents of the specified container
- See Also:
-
minimumLayoutSize
Returns the minimum dimensions needed to layout the visible components contained in the specified target container.- Specified by:
minimumLayoutSize
in interfaceLayoutManager
- Overrides:
minimumLayoutSize
in classFlowLayout
- Parameters:
target
- the component which needs to be laid out- Returns:
- the minimum dimensions to lay out the subcomponents of the specified container
- See Also:
-
moveComponents
protected void moveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd, boolean ltr, se.datadosen.component.Ruler ruler) Centers the elements in the specified row, if there is any slack.- Parameters:
target
- the component which needs to be movedx
- the x coordinatey
- the y coordinatewidth
- the width dimensionsheight
- the height dimensionsrowStart
- the beginning of the rowrowEnd
- the the ending of the row
-
relMove
-
adjustAlignment
-
layoutContainer
Lays out the container. This method lets each component take its preferred size by reshaping the components in the target container in order to satisfy the constraints of thisFlowLayout
object.- Specified by:
layoutContainer
in interfaceLayoutManager
- Overrides:
layoutContainer
in classFlowLayout
- Parameters:
target
- the specified component being laid out- See Also:
-