public class FlowPane extends Pane
A horizontal flowpane (the default) will layout nodes in rows, wrapping at the flowpane's width. A vertical flowpane lays out nodes in columns, wrapping at the flowpane's height. If the flowpane has a border and/or padding set, the content will be flowed within those insets.
FlowPane's prefWrapLength property establishes its preferred width (for horizontal) or preferred height (for vertical). Applications should set prefWrapLength if the default value (400) doesn't suffice. Note that prefWrapLength is used only for calculating the preferred size and may not reflect the actual wrapping dimension, which tracks the actual size of the flowpane.
The alignment property controls how the rows and columns are aligned within the bounds of the flowpane and defaults to Pos.TOP_LEFT. It is also possible to control the alignment of nodes within the rows and columns by setting rowValignment for horizontal or columnHalignment for vertical.
Example of a horizontal flowpane:
Image images[] = { ... };
FlowPane flow = new FlowPane();
flow.setVgap(8);
flow.setHgap(4);
flow.setPrefWrapLength(300); // preferred width = 300
for (int i = 0; i < images.length; i++) {
flow.getChildren().add(new ImageView(image[i]);
}
Example of a vertical flowpane:
FlowPane flow = new FlowPane(Orientation.VERTICAL);
flow.setColumnHalignment(HPos.LEFT); // align labels on left
flow.setPrefWrapLength(200); // preferred height = 200
for (int i = 0; i < titles.size(); i++) {
flow.getChildren().add(new Label(titles[i]);
}
FlowPane lays out each managed child regardless of the child's visible property value; unmanaged children are ignored for all layout calculations.
FlowPane may be styled with backgrounds and borders using CSS. See
Region
superclass for details.
A flowpane's parent will resize the flowpane within the flowpane's resizable range during layout. By default the flowpane computes this range based on its content as outlined in the tables below.
width | height | |
---|---|---|
minimum | left/right insets plus largest of children's pref widths | top/bottom insets plus height required to display all children at their preferred heights when wrapped at a specified width |
preferred | left/right insets plus prefWrapLength | top/bottom insets plus height required to display all children at their pref heights when wrapped at a specified width |
maximum | Double.MAX_VALUE | Double.MAX_VALUE |
width | height | |
---|---|---|
minimum | left/right insets plus width required to display all children at their preferred widths when wrapped at a specified height | top/bottom insets plus largest of children's pref heights |
preferred | left/right insets plus width required to display all children at their pref widths when wrapped at the specified height | top/bottom insets plus prefWrapLength |
maximum | Double.MAX_VALUE | Double.MAX_VALUE |
A flowpane's unbounded maximum width and height are an indication to the parent that it may be resized beyond its preferred size to fill whatever space is assigned to it.
FlowPane provides properties for setting the size range directly. These properties default to the sentinel value Region.USE_COMPUTED_SIZE, however the application may set them to other values as needed:
flowPane.setMaxWidth(500);
Applications may restore the computed values by setting these properties back
to Region.USE_COMPUTED_SIZE.
FlowPane does not clip its content by default, so it is possible that children's bounds may extend outside its own bounds if a child's pref size is larger than the space flowpane has to allocate for it.
Type | Property and Description |
---|---|
<any> |
alignment
The overall alignment of the flowpane's content within its width and height.
|
<any> |
columnHalignment
The horizontal alignment of nodes within each column of a vertical flowpane.
|
DoubleProperty |
hgap
The amount of horizontal space between each node in a horizontal flowpane
or the space between columns in a vertical flowpane.
|
<any> |
orientation
The orientation of this flowpane.
|
DoubleProperty |
prefWrapLength
The preferred width where content should wrap in a horizontal flowpane or
the preferred height where content should wrap in a vertical flowpane.
|
<any> |
rowValignment
The vertical alignment of nodes within each row of a horizontal flowpane.
|
DoubleProperty |
vgap
The amount of vertical space between each node in a vertical flowpane
or the space between rows in a horizontal flowpane.
|
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, heightProperty, insetsProperty, maxHeightProperty, maxWidthProperty, minHeightProperty, minWidthProperty, opaqueInsetsProperty, paddingProperty, prefHeightProperty, prefWidthProperty, scaleShapeProperty, shapeProperty, snapToPixelProperty, widthProperty
Modifier and Type | Class and Description |
---|---|
private static class |
FlowPane.LayoutRect |
private static class |
FlowPane.Run |
private static class |
FlowPane.StyleableProperties
*
Stylesheet Handling *
*
|
Modifier and Type | Field and Description |
---|---|
private <any> |
alignment |
private <any> |
columnHalignment |
(package private) boolean |
computingRuns |
private DoubleProperty |
hgap |
private double |
lastMaxRunLength |
private static java.lang.String |
MARGIN_CONSTRAINT
BEGIN static methods
|
private static <any> |
marginAccessor |
private <any> |
orientation |
private DoubleProperty |
prefWrapLength |
private <any> |
rowValignment |
private java.util.List<FlowPane.Run> |
runs |
private DoubleProperty |
vgap |
TEMP_VEC2D, USE_COMPUTED_SIZE, USE_PREF_SIZE
Constructor and Description |
---|
FlowPane()
Creates a horizontal FlowPane layout with hgap/vgap = 0.
|
FlowPane(double hgap,
double vgap)
Creates a horizontal FlowPane layout with the specified hgap/vgap.
|
FlowPane(double hgap,
double vgap,
Node... children)
Creates a horizontal FlowPane layout with the specified hgap/vgap.
|
FlowPane(Node... children)
Creates a horizontal FlowPane layout with hgap/vgap = 0.
|
FlowPane(Orientation orientation)
Creates a FlowPane layout with the specified orientation and hgap/vgap = 0.
|
FlowPane(Orientation orientation,
double hgap,
double vgap)
Creates a FlowPane layout with the specified orientation and hgap/vgap.
|
FlowPane(Orientation orientation,
double hgap,
double vgap,
Node... children)
Creates a FlowPane layout with the specified orientation and hgap/vgap.
|
FlowPane(Orientation orientation,
Node... children)
Creates a FlowPane layout with the specified orientation and hgap/vgap = 0.
|
Modifier and Type | Method and Description |
---|---|
<any> |
alignmentProperty()
The overall alignment of the flowpane's content within its width and height.
|
static void |
clearConstraints(Node child)
Removes all flowpane constraints from the child node.
|
<any> |
columnHalignmentProperty()
The horizontal alignment of nodes within each column of a vertical flowpane.
|
private double |
computeContentHeight(java.util.List<FlowPane.Run> runs) |
private double |
computeContentWidth(java.util.List<FlowPane.Run> runs) |
protected double |
computeMinHeight(double width)
Computes the minimum height of this region.
|
protected double |
computeMinWidth(double height)
Computes the minimum width of this region.
|
protected double |
computePrefHeight(double forWidth)
Computes the preferred height of this region for the given width;
Region subclasses should override this method to return an appropriate
value based on their content and layout strategy.
|
protected double |
computePrefWidth(double forHeight)
Computes the preferred width of this region for the given height.
|
Pos |
getAlignment()
Gets the value of the property alignment.
|
private Pos |
getAlignmentInternal() |
static java.util.List<<any>> |
getClassCssMetaData() |
HPos |
getColumnHalignment()
Gets the value of the property columnHalignment.
|
private HPos |
getColumnHalignmentInternal() |
Orientation |
getContentBias() |
java.util.List<<any>> |
getCssMetaData() |
double |
getHgap()
Gets the value of the property hgap.
|
static Insets |
getMargin(Node child)
Returns the child's margin constraint if set.
|
Orientation |
getOrientation()
Gets the value of the property orientation.
|
double |
getPrefWrapLength()
Gets the value of the property prefWrapLength.
|
VPos |
getRowValignment()
Gets the value of the property rowValignment.
|
private VPos |
getRowValignmentInternal() |
private java.util.List<FlowPane.Run> |
getRuns(double maxRunLength) |
double |
getVgap()
Gets the value of the property vgap.
|
DoubleProperty |
hgapProperty()
The amount of horizontal space between each node in a horizontal flowpane
or the space between columns in a vertical flowpane.
|
protected void |
layoutChildren() |
private void |
normalizeRun(FlowPane.Run run,
double runOffset) |
<any> |
orientationProperty()
The orientation of this flowpane.
|
DoubleProperty |
prefWrapLengthProperty()
The preferred width where content should wrap in a horizontal flowpane or
the preferred height where content should wrap in a vertical flowpane.
|
void |
requestLayout() |
<any> |
rowValignmentProperty()
The vertical alignment of nodes within each row of a horizontal flowpane.
|
void |
setAlignment(Pos value)
Sets the value of the property alignment.
|
void |
setColumnHalignment(HPos value)
Sets the value of the property columnHalignment.
|
void |
setHgap(double value)
Sets the value of the property hgap.
|
static void |
setMargin(Node child,
Insets value)
Sets the margin for the child when contained by a flowpane.
|
void |
setOrientation(Orientation value)
Sets the value of the property orientation.
|
void |
setPrefWrapLength(double value)
Sets the value of the property prefWrapLength.
|
void |
setRowValignment(VPos value)
Sets the value of the property rowValignment.
|
void |
setVgap(double value)
Sets the value of the property vgap.
|
DoubleProperty |
vgapProperty()
The amount of vertical space between each node in a vertical flowpane
or the space between rows in a horizontal flowpane.
|
getChildren, getConstraint, setConstraint
addImageListener, adjustHeightByMargin, adjustWidthByMargin, backgroundProperty, borderProperty, boundedNodeSizeWithBias, boundedSize, cacheShapeProperty, centerShapeProperty, computeChildMaxAreaHeight, computeChildMaxAreaWidth, computeChildMinAreaHeight, computeChildMinAreaHeight, computeChildMinAreaWidth, computeChildMinAreaWidth, computeChildPrefAreaHeight, computeChildPrefAreaHeight, computeChildPrefAreaWidth, computeChildPrefAreaWidth, computeMaxHeight, computeMaxMinAreaHeight, computeMaxMinAreaHeight, computeMaxMinAreaHeight, computeMaxMinAreaWidth, computeMaxMinAreaWidth, computeMaxMinAreaWidth, computeMaxPrefAreaHeight, computeMaxPrefAreaHeight, computeMaxPrefAreaHeight, computeMaxPrefAreaWidth, computeMaxPrefAreaWidth, computeMaxPrefAreaWidth, computeMaxWidth, computeXOffset, computeYOffset, createDoubleArray, getAreaBaselineOffset, getAreaBaselineOffset, getAreaBaselineOffset, getAreaBaselineOffset, getAreaBaselineOffset, getAreaBaselineOffset, getBackground, getBorder, getHeight, getInsets, getMaxBaselineComplement, getMaxHeight, getMaxWidth, getMinBaselineComplement, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefBaselineComplement, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, removeImageListener, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPortionX, snapPortionY, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
public final <any> orientationProperty
getOrientation()
,
setOrientation(Orientation)
public final DoubleProperty hgapProperty
getHgap()
,
setHgap(double)
public final DoubleProperty vgapProperty
getVgap()
,
setVgap(double)
public final DoubleProperty prefWrapLengthProperty
This value is used only to compute the preferred size of the flowpane and may not reflect the actual width or height, which may change if the flowpane is resized to something other than its preferred size.
Applications should initialize this value to define a reasonable span for wrapping the content.
getPrefWrapLength()
,
setPrefWrapLength(double)
public final <any> alignmentProperty
For a horizontal flowpane, each row will be aligned within the flowpane's width using the alignment's hpos value, and the rows will be aligned within the flowpane's height using the alignment's vpos value.
For a vertical flowpane, each column will be aligned within the flowpane's height using the alignment's vpos value, and the columns will be aligned within the flowpane's width using the alignment's hpos value.
getAlignment()
,
setAlignment(Pos)
public final <any> columnHalignmentProperty
getColumnHalignment()
,
setColumnHalignment(HPos)
public final <any> rowValignmentProperty
getRowValignment()
,
setRowValignment(VPos)
private static final java.lang.String MARGIN_CONSTRAINT
private static final <any> marginAccessor
private <any> orientation
private DoubleProperty hgap
private DoubleProperty vgap
private DoubleProperty prefWrapLength
private <any> alignment
private <any> columnHalignment
private <any> rowValignment
private java.util.List<FlowPane.Run> runs
private double lastMaxRunLength
boolean computingRuns
public FlowPane()
public FlowPane(Orientation orientation)
orientation
- the direction the tiles should flow & wrappublic FlowPane(double hgap, double vgap)
hgap
- the amount of horizontal space between each tilevgap
- the amount of vertical space between each tilepublic FlowPane(Orientation orientation, double hgap, double vgap)
orientation
- the direction the tiles should flow & wraphgap
- the amount of horizontal space between each tilevgap
- the amount of vertical space between each tilepublic FlowPane(Node... children)
children
- The initial set of children for this pane.public FlowPane(Orientation orientation, Node... children)
orientation
- the direction the tiles should flow & wrapchildren
- The initial set of children for this pane.public FlowPane(double hgap, double vgap, Node... children)
hgap
- the amount of horizontal space between each tilevgap
- the amount of vertical space between each tilechildren
- The initial set of children for this pane.public FlowPane(Orientation orientation, double hgap, double vgap, Node... children)
orientation
- the direction the tiles should flow & wraphgap
- the amount of horizontal space between each tilevgap
- the amount of vertical space between each tilechildren
- The initial set of children for this pane.public static void setMargin(Node child, Insets value)
child
- the child node of a flowpanevalue
- the margin of space around the childpublic static Insets getMargin(Node child)
child
- the child node of a flowpanepublic static void clearConstraints(Node child)
child
- the child nodepublic final <any> orientationProperty()
getOrientation()
,
setOrientation(Orientation)
public final void setOrientation(Orientation value)
public final Orientation getOrientation()
public final DoubleProperty hgapProperty()
getHgap()
,
setHgap(double)
public final void setHgap(double value)
public final double getHgap()
public final DoubleProperty vgapProperty()
getVgap()
,
setVgap(double)
public final void setVgap(double value)
public final double getVgap()
public final DoubleProperty prefWrapLengthProperty()
This value is used only to compute the preferred size of the flowpane and may not reflect the actual width or height, which may change if the flowpane is resized to something other than its preferred size.
Applications should initialize this value to define a reasonable span for wrapping the content.
getPrefWrapLength()
,
setPrefWrapLength(double)
public final void setPrefWrapLength(double value)
public final double getPrefWrapLength()
public final <any> alignmentProperty()
For a horizontal flowpane, each row will be aligned within the flowpane's width using the alignment's hpos value, and the rows will be aligned within the flowpane's height using the alignment's vpos value.
For a vertical flowpane, each column will be aligned within the flowpane's height using the alignment's vpos value, and the columns will be aligned within the flowpane's width using the alignment's hpos value.
getAlignment()
,
setAlignment(Pos)
public final void setAlignment(Pos value)
public final Pos getAlignment()
private Pos getAlignmentInternal()
public final <any> columnHalignmentProperty()
getColumnHalignment()
,
setColumnHalignment(HPos)
public final void setColumnHalignment(HPos value)
public final HPos getColumnHalignment()
private HPos getColumnHalignmentInternal()
public final <any> rowValignmentProperty()
getRowValignment()
,
setRowValignment(VPos)
public final void setRowValignment(VPos value)
public final VPos getRowValignment()
private VPos getRowValignmentInternal()
public Orientation getContentBias()
protected double computeMinWidth(double height)
Region
computeMinWidth
in class Region
protected double computeMinHeight(double width)
Region
computeMinHeight
in class Region
protected double computePrefWidth(double forHeight)
Region
computePrefWidth
in class Region
protected double computePrefHeight(double forWidth)
Region
computePrefHeight
in class Region
public void requestLayout()
private java.util.List<FlowPane.Run> getRuns(double maxRunLength)
private void normalizeRun(FlowPane.Run run, double runOffset)
private double computeContentWidth(java.util.List<FlowPane.Run> runs)
private double computeContentHeight(java.util.List<FlowPane.Run> runs)
protected void layoutChildren()
public static java.util.List<<any>> getClassCssMetaData()
public java.util.List<<any>> getCssMetaData()
getCssMetaData
in class Region