APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javafx.scene.layout

public Class FlowPane

extends Pane
Class Inheritance
Imports
java.util.ArrayList, .Collections, .List, javafx.beans.property.DoubleProperty, .DoublePropertyBase, .ObjectProperty, javafx.css.CssMetaData, .StyleableDoubleProperty, .StyleableObjectProperty, .StyleableProperty, .Styleable, javafx.geometry.HPos, .Insets, .Orientation, .Pos, .VPos, javafx.scene.Node, javafx.css.converter.EnumConverter, .SizeConverter, javafx.util.Callback

FlowPane lays out its children in a flow that wraps at the flowpane's boundary.

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.

Resizable Range

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.

Horizontal
widthheight
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_VALUEDouble.MAX_VALUE

Vertical
widthheight
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_VALUEDouble.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.

Since
JavaFX 2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private ObjectProperty<Pos>
private ObjectProperty<HPos>
pack-priv boolean
private DoubleProperty
private double
private static final String
private static final Callback<Node, Insets>
private ObjectProperty<Orientation>
private DoubleProperty
private ObjectProperty<VPos>
private List<FlowPane.Run>
private DoubleProperty

Constructor Summary

AccessConstructor and Description
public
FlowPane()

Creates a horizontal FlowPane layout with hgap/vgap = 0.

public
FlowPane(Orientation
the direction the tiles should flow & wrap
orientation
)

Creates a FlowPane layout with the specified orientation and hgap/vgap = 0.

public
FlowPane(double
the amount of horizontal space between each tile
hgap
,
double
the amount of vertical space between each tile
vgap
)

Creates a horizontal FlowPane layout with the specified hgap/vgap.

public
FlowPane(Orientation
the direction the tiles should flow & wrap
orientation
,
double
the amount of horizontal space between each tile
hgap
,
double
the amount of vertical space between each tile
vgap
)

Creates a FlowPane layout with the specified orientation and hgap/vgap.

public
FlowPane(Node...
The initial set of children for this pane.
children
)

Creates a horizontal FlowPane layout with hgap/vgap = 0.

public
FlowPane(Orientation
the direction the tiles should flow & wrap
orientation
,
Node...
The initial set of children for this pane.
children
)

Creates a FlowPane layout with the specified orientation and hgap/vgap = 0.

public
FlowPane(double
the amount of horizontal space between each tile
hgap
,
double
the amount of vertical space between each tile
vgap
,
Node...
The initial set of children for this pane.
children
)

Creates a horizontal FlowPane layout with the specified hgap/vgap.

public
FlowPane(Orientation
the direction the tiles should flow & wrap
orientation
,
double
the amount of horizontal space between each tile
hgap
,
double
the amount of vertical space between each tile
vgap
,
Node...
The initial set of children for this pane.
children
)

Creates a FlowPane layout with the specified orientation and hgap/vgap.

Method Summary

Modifier and TypeMethod and Description
public final ObjectProperty<Pos>

Returns:

the overall alignment of the flowpane's content within its width and height
alignmentProperty
()

The overall alignment of the flowpane's content within its width and height.

public static void
clearConstraints(Node
the child node
child
)

Removes all flowpane constraints from the child node.

public final ObjectProperty<HPos>

Returns:

the horizontal alignment of nodes within each column of a vertical flowpane
columnHalignmentProperty
()

The horizontal alignment of nodes within each column of a vertical flowpane.

private double
private double
protected double
computeMinHeight(double width)

Overrides javafx.scene.layout.Region.computeMinHeight.

Computes the minimum height of this region.

protected double
computeMinWidth(double height)

Overrides javafx.scene.layout.Region.computeMinWidth.

Computes the minimum width of this region.

protected double
computePrefHeight(double forWidth)

Overrides javafx.scene.layout.Region.computePrefHeight.

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)

Overrides javafx.scene.layout.Region.computePrefWidth.

Computes the preferred width of this region for the given height.

public final Pos
private Pos
public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.layout.Region.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public final HPos
private HPos
public Orientation
getContentBias()

Overrides javafx.scene.Node.getContentBias.

Returns the orientation of a node's resizing bias for layout purposes.

public List<CssMetaData<? extends Styleable, ?>>
getCssMetaData()

Overrides javafx.scene.layout.Region.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

public final double
public static Insets

Returns:

the margin for the child or null if no margin was set
getMargin
(Node
the child node of a flowpane
child
)

Returns the child's margin constraint if set.

public final Orientation
public final double
public final VPos
private VPos
private List<FlowPane.Run>
getRuns(double maxRunLength)

public final double
public final DoubleProperty

Returns:

the amount of horizontal space between each node in a horizontal flowpane or the space between columns in a vertical flowpane
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()

Overrides javafx.scene.Parent.layoutChildren.

Invoked during the layout pass to layout the children in this Parent.

private void
normalizeRun(final FlowPane.Run run, double runOffset)

public final ObjectProperty<Orientation>

Returns:

the orientation of this flowpane
orientationProperty
()

The orientation of this flowpane.

public final DoubleProperty

Returns:

the preferred width where content should wrap in a horizontal flowpane or the preferred height where content should wrap in a vertical flowpane
prefWrapLengthProperty
()

The preferred width where content should wrap in a horizontal flowpane or the preferred height where content should wrap in a vertical flowpane.

public void
requestLayout()

Overrides javafx.scene.Parent.requestLayout.

Requests a layout pass to be performed before the next scene is rendered.

public final ObjectProperty<VPos>

Returns:

the vertical alignment of nodes within each row of a horizontal flowpane
rowValignmentProperty
()

The vertical alignment of nodes within each row of a horizontal flowpane.

public final void
public final void
public final void
setHgap(double value)

public static void
setMargin(Node
the child node of a flowpane
child
,
Insets
the margin of space around the child
value
)

Sets the margin for the child when contained by a flowpane.

public final void
public final void
setPrefWrapLength(double value)

public final void
public final void
setVgap(double value)

public final DoubleProperty

Returns:

the amount of vertical space between each node in a vertical flowpane or the space between rows in a horizontal flowpane
vgapProperty
()

The amount of vertical space between each node in a vertical flowpane or the space between rows in a horizontal flowpane.

Inherited from javafx.scene.layout.Pane:
getChildrengetConstraintsetConstraint

Field Detail

alignmentback to summary
private ObjectProperty<Pos> alignment
columnHalignmentback to summary
private ObjectProperty<HPos> columnHalignment
computingRunsback to summary
pack-priv boolean computingRuns
hgapback to summary
private DoubleProperty hgap
lastMaxRunLengthback to summary
private double lastMaxRunLength
MARGIN_CONSTRAINTback to summary
private static final String MARGIN_CONSTRAINT
marginAccessorback to summary
private static final Callback<Node, Insets> marginAccessor
orientationback to summary
private ObjectProperty<Orientation> orientation
prefWrapLengthback to summary
private DoubleProperty prefWrapLength
rowValignmentback to summary
private ObjectProperty<VPos> rowValignment
runsback to summary
private List<FlowPane.Run> runs
vgapback to summary
private DoubleProperty vgap

Constructor Detail

FlowPaneback to summary
public FlowPane()

Creates a horizontal FlowPane layout with hgap/vgap = 0.

FlowPaneback to summary
public FlowPane(Orientation orientation)

Creates a FlowPane layout with the specified orientation and hgap/vgap = 0.

Parameters
orientation:Orientation

the direction the tiles should flow & wrap

FlowPaneback to summary
public FlowPane(double hgap, double vgap)

Creates a horizontal FlowPane layout with the specified hgap/vgap.

Parameters
hgap:double

the amount of horizontal space between each tile

vgap:double

the amount of vertical space between each tile

FlowPaneback to summary
public FlowPane(Orientation orientation, double hgap, double vgap)

Creates a FlowPane layout with the specified orientation and hgap/vgap.

Parameters
orientation:Orientation

the direction the tiles should flow & wrap

hgap:double

the amount of horizontal space between each tile

vgap:double

the amount of vertical space between each tile

FlowPaneback to summary
public FlowPane(Node... children)

Creates a horizontal FlowPane layout with hgap/vgap = 0.

Parameters
children:Node[]

The initial set of children for this pane.

Since
JavaFX 8.0
FlowPaneback to summary
public FlowPane(Orientation orientation, Node... children)

Creates a FlowPane layout with the specified orientation and hgap/vgap = 0.

Parameters
orientation:Orientation

the direction the tiles should flow & wrap

children:Node[]

The initial set of children for this pane.

Since
JavaFX 8.0
FlowPaneback to summary
public FlowPane(double hgap, double vgap, Node... children)

Creates a horizontal FlowPane layout with the specified hgap/vgap.

Parameters
hgap:double

the amount of horizontal space between each tile

vgap:double

the amount of vertical space between each tile

children:Node[]

The initial set of children for this pane.

Since
JavaFX 8.0
FlowPaneback to summary
public FlowPane(Orientation orientation, double hgap, double vgap, Node... children)

Creates a FlowPane layout with the specified orientation and hgap/vgap.

Parameters
orientation:Orientation

the direction the tiles should flow & wrap

hgap:double

the amount of horizontal space between each tile

vgap:double

the amount of vertical space between each tile

children:Node[]

The initial set of children for this pane.

Since
JavaFX 8.0

Method Detail

alignmentPropertyback to summary
public final ObjectProperty<Pos> alignmentProperty()

The overall alignment of the flowpane's content within its width and height.

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.

Returns:ObjectProperty<Pos>

the overall alignment of the flowpane's content within its width and height

clearConstraintsback to summary
public static void clearConstraints(Node child)

Removes all flowpane constraints from the child node.

Parameters
child:Node

the child node

columnHalignmentPropertyback to summary
public final ObjectProperty<HPos> columnHalignmentProperty()

The horizontal alignment of nodes within each column of a vertical flowpane. The property is ignored for horizontal flowpanes.

Returns:ObjectProperty<HPos>

the horizontal alignment of nodes within each column of a vertical flowpane

computeContentHeightback to summary
private double computeContentHeight(List<FlowPane.Run> runs)
computeContentWidthback to summary
private double computeContentWidth(List<FlowPane.Run> runs)
computeMinHeightback to summary
protected double computeMinHeight(double width)

Overrides javafx.scene.layout.Region.computeMinHeight.

Doc from javafx.scene.layout.Region.computeMinHeight.

Computes the minimum height of this region. Returns the sum of the top and bottom insets by default. Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a HORIZONTAL content bias, then the width parameter can be ignored.

Annotations
@Override
computeMinWidthback to summary
protected double computeMinWidth(double height)

Overrides javafx.scene.layout.Region.computeMinWidth.

Doc from javafx.scene.layout.Region.computeMinWidth.

Computes the minimum width of this region. Returns the sum of the left and right insets by default. region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a VERTICAL content bias, then the height parameter can be ignored.

Annotations
@Override
computePrefHeightback to summary
protected double computePrefHeight(double forWidth)

Overrides javafx.scene.layout.Region.computePrefHeight.

Doc from javafx.scene.layout.Region.computePrefHeight.

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. If the subclass doesn't have a HORIZONTAL content bias, then the width parameter can be ignored.

Annotations
@Override
computePrefWidthback to summary
protected double computePrefWidth(double forHeight)

Overrides javafx.scene.layout.Region.computePrefWidth.

Doc from javafx.scene.layout.Region.computePrefWidth.

Computes the preferred width of this region for the given height. Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a VERTICAL content bias, then the height parameter can be ignored.

Annotations
@Override
getAlignmentback to summary
public final Pos getAlignment()
getAlignmentInternalback to summary
private Pos getAlignmentInternal()
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.layout.Region.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

Since
JavaFX 8.0
getColumnHalignmentback to summary
public final HPos getColumnHalignment()
getColumnHalignmentInternalback to summary
private HPos getColumnHalignmentInternal()
getContentBiasback to summary
public Orientation getContentBias()

Overrides javafx.scene.Node.getContentBias.

Doc from javafx.scene.Node.getContentBias.

Returns the orientation of a node's resizing bias for layout purposes. If the node type has no bias, returns null. If the node is resizable and it's height depends on its width, returns HORIZONTAL, else if its width depends on its height, returns VERTICAL.

Resizable subclasses should override this method to return an appropriate value.

Annotations
@Override
getCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData()

Overrides javafx.scene.layout.Region.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

Doc from javafx.scene.layout.Region.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

Annotations
@Override
Since
JavaFX 8.0
getHgapback to summary
public final double getHgap()
getMarginback to summary
public static Insets getMargin(Node child)

Returns the child's margin constraint if set.

Parameters
child:Node

the child node of a flowpane

Returns:Insets

the margin for the child or null if no margin was set

getOrientationback to summary
public final Orientation getOrientation()
getPrefWrapLengthback to summary
public final double getPrefWrapLength()
getRowValignmentback to summary
public final VPos getRowValignment()
getRowValignmentInternalback to summary
private VPos getRowValignmentInternal()
getRunsback to summary
private List<FlowPane.Run> getRuns(double maxRunLength)
getVgapback to summary
public final double getVgap()
hgapPropertyback to summary
public final DoubleProperty hgapProperty()

The amount of horizontal space between each node in a horizontal flowpane or the space between columns in a vertical flowpane.

Returns:DoubleProperty

the amount of horizontal space between each node in a horizontal flowpane or the space between columns in a vertical flowpane

layoutChildrenback to summary
protected void layoutChildren()

Overrides javafx.scene.Parent.layoutChildren.

Doc from javafx.scene.Parent.layoutChildren.

Invoked during the layout pass to layout the children in this Parent. By default it will only set the size of managed, resizable content to their preferred sizes and does not do any node positioning.

Subclasses should override this function to layout content as needed.

Annotations
@Override
normalizeRunback to summary
private void normalizeRun(final FlowPane.Run run, double runOffset)
orientationPropertyback to summary
public final ObjectProperty<Orientation> orientationProperty()

The orientation of this flowpane. A horizontal flowpane lays out children left to right, wrapping at the flowpane's width boundary. A vertical flowpane lays out children top to bottom, wrapping at the flowpane's height. The default is horizontal.

Returns:ObjectProperty<Orientation>

the orientation of this flowpane

prefWrapLengthPropertyback to summary
public final 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.

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.

Returns:DoubleProperty

the preferred width where content should wrap in a horizontal flowpane or the preferred height where content should wrap in a vertical flowpane

requestLayoutback to summary
public void requestLayout()

Overrides javafx.scene.Parent.requestLayout.

Doc from javafx.scene.Parent.requestLayout.

Requests a layout pass to be performed before the next scene is rendered. This is batched up asynchronously to happen once per "pulse", or frame of animation.

If this parent is either a scene root or unmanaged, then it will be added directly to the scene's dirty layout list, otherwise requestParentLayout will be invoked.

Annotations
@Override
rowValignmentPropertyback to summary
public final ObjectProperty<VPos> rowValignmentProperty()

The vertical alignment of nodes within each row of a horizontal flowpane. If this property is set to VPos.BASELINE, then the flowpane will always resize children to their preferred heights, rather than expanding heights to fill the row height. The property is ignored for vertical flowpanes.

Returns:ObjectProperty<VPos>

the vertical alignment of nodes within each row of a horizontal flowpane

setAlignmentback to summary
public final void setAlignment(Pos value)
setColumnHalignmentback to summary
public final void setColumnHalignment(HPos value)
setHgapback to summary
public final void setHgap(double value)
setMarginback to summary
public static void setMargin(Node child, Insets value)

Sets the margin for the child when contained by a flowpane. If set, the flowpane will layout it out with the margin space around it. Setting the value to null will remove the constraint.

Parameters
child:Node

the child node of a flowpane

value:Insets

the margin of space around the child

setOrientationback to summary
public final void setOrientation(Orientation value)
setPrefWrapLengthback to summary
public final void setPrefWrapLength(double value)
setRowValignmentback to summary
public final void setRowValignment(VPos value)
setVgapback to summary
public final void setVgap(double value)
vgapPropertyback to summary
public final DoubleProperty vgapProperty()

The amount of vertical space between each node in a vertical flowpane or the space between rows in a horizontal flowpane.

Returns:DoubleProperty

the amount of vertical space between each node in a vertical flowpane or the space between rows in a horizontal flowpane

javafx.scene.layout back to summary

private Class FlowPane.LayoutRect

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv double
public Node
pack-priv double
pack-priv double
x

pack-priv double
y

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

heightback to summary
pack-priv double height
nodeback to summary
public Node node
widthback to summary
pack-priv double width
xback to summary
pack-priv double x
yback to summary
pack-priv double y

Constructor Detail

LayoutRectback to summary
private LayoutRect()

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
javafx.scene.layout back to summary

private Class FlowPane.Run

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv double
pack-priv double
pack-priv ArrayList<FlowPane.LayoutRect>
pack-priv double

Constructor Summary

AccessConstructor and Description
private
Run()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baselineOffsetback to summary
pack-priv double baselineOffset
heightback to summary
pack-priv double height
rectsback to summary
pack-priv ArrayList<FlowPane.LayoutRect> rects
widthback to summary
pack-priv double width

Constructor Detail

Runback to summary
private Run()
javafx.scene.layout back to summary

private Class FlowPane.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<FlowPane, Pos>
private static final CssMetaData<FlowPane, HPos>
private static final CssMetaData<FlowPane, Number>
private static final CssMetaData<FlowPane, Orientation>
private static final CssMetaData<FlowPane, VPos>
private static final List<CssMetaData<? extends Styleable, ?>>
private static final CssMetaData<FlowPane, Number>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALIGNMENTback to summary
private static final CssMetaData<FlowPane, Pos> ALIGNMENT
COLUMN_HALIGNMENTback to summary
private static final CssMetaData<FlowPane, HPos> COLUMN_HALIGNMENT
HGAPback to summary
private static final CssMetaData<FlowPane, Number> HGAP
ORIENTATIONback to summary
private static final CssMetaData<FlowPane, Orientation> ORIENTATION
ROW_VALIGNMENTback to summary
private static final CssMetaData<FlowPane, VPos> ROW_VALIGNMENT
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES
VGAPback to summary
private static final CssMetaData<FlowPane, Number> VGAP

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()