public class BorderPane extends Pane
The top and bottom children will be resized to their preferred heights and extend the width of the border pane. The left and right children will be resized to their preferred widths and extend the length between the top and bottom nodes. And the center node will be resized to fill the available space in the middle. Any of the positions may be null. Example:
BorderPane borderPane = new BorderPane();
ToolBar toolbar = new ToolBar();
HBox statusbar = new HBox();
Node appContent = new AppContentNode();
borderPane.setTop(toolbar);
borderPane.setCenter(appContent);
borderPane.setBottom(statusbar);
Borderpanes may be styled with backgrounds and borders using CSS. See
Region
superclass for details.
BorderPane honors the minimum, preferred, and maximum sizes of its children. If the child's resizable range prevents it from be resized to fit within its position, it will be aligned relative to the space using a default alignment as follows:
BorderPane lays out each child set in the five positions regardless of the child's visible property value; unmanaged children are ignored.
BorderPane is commonly used as the root of a Scene
,
in which case its size will track the size of the scene. If the scene or stage
size has not been directly set by the application, the scene size will be
initialized to the border pane's preferred size. However, if a border pane
has a parent other than the scene, that parent will resize the border pane within
the border pane's resizable range during layout. By default the border pane
computes this range based on its content as outlined in the table below.
width | height | |
---|---|---|
minimum | left/right insets plus width required to display right/left children at their pref widths and top/bottom/center with at least their min widths | top/bottom insets plus height required to display top/bottom children at their pref heights and left/right/center with at least their min heights |
preferred | left/right insets plus width required to display top/right/bottom/left/center children with at least their pref widths | top/bottom insets plus height required to display top/right/bottom/left/center children with at least their pref heights |
maximum | Double.MAX_VALUE | Double.MAX_VALUE |
A border pane'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.
BorderPane 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:
borderPane.setPrefSize(500,400);
Applications may restore the computed values by setting these properties back
to Region.USE_COMPUTED_SIZE.
BorderPane 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 min size prevents it from being fit within it space.
An application may set constraints on individual children to customize BorderPane's layout. For each constraint, BorderPane provides a static method for setting it on the child.
Constraint | Type | Description |
---|---|---|
alignment | javafx.geometry.Pos | The alignment of the child within its area of the border pane. |
margin | javafx.geometry.Insets | Margin space around the outside of the child. |
Example:
ListView list = new ListView();
BorderPane.setAlignment(list, Pos.TOP_LEFT);
BorderPane.setMargin(list, new Insets(12,12,12,12));
borderPane.setCenter(list);
Type | Property and Description |
---|---|
<any> |
bottom
The node placed on the bottom edge of this border pane.
|
<any> |
center
The node placed in the center of this border pane.
|
<any> |
left
The node placed on the left edge of this border pane.
|
<any> |
right
The node placed on the right edge of this border pane.
|
<any> |
top
The node placed on the top edge of this border pane.
|
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 class |
BorderPane.BorderPositionProperty
*
Private Inner Class *
*
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ALIGNMENT |
private <any> |
bottom |
private <any> |
center |
private <any> |
left |
private static java.lang.String |
MARGIN
BEGIN static methods
|
private <any> |
right |
private <any> |
top |
TEMP_VEC2D, USE_COMPUTED_SIZE, USE_PREF_SIZE
Constructor and Description |
---|
BorderPane()
Creates a BorderPane layout.
|
BorderPane(Node center)
Creates an BorderPane layout with the given Node as the center of the BorderPane.
|
BorderPane(Node center,
Node top,
Node right,
Node bottom,
Node left)
Creates an BorderPane layout with the given Nodes to use for each of the main
layout areas of the Border Pane.
|
Modifier and Type | Method and Description |
---|---|
<any> |
bottomProperty()
The node placed on the bottom edge of this border pane.
|
<any> |
centerProperty()
The node placed in the center of this border pane.
|
private boolean |
childHasContentBias(Node child,
Orientation orientation) |
static void |
clearConstraints(Node child)
Removes all border pane constraints from the child node.
|
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 width)
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 height)
Computes the preferred width of this region for the given height.
|
static Pos |
getAlignment(Node child)
Returns the child's alignment constraint if set.
|
private double |
getAreaHeight(Node child,
double width,
boolean minimum) |
private double |
getAreaWidth(Node child,
double height,
boolean minimum) |
Node |
getBottom()
Gets the value of the property bottom.
|
Node |
getCenter()
Gets the value of the property center.
|
Orientation |
getContentBias() |
Node |
getLeft()
Gets the value of the property left.
|
static Insets |
getMargin(Node child)
Returns the child's margin constraint if set.
|
private static Insets |
getNodeMargin(Node child) |
Node |
getRight()
Gets the value of the property right.
|
Node |
getTop()
Gets the value of the property top.
|
protected void |
layoutChildren() |
<any> |
leftProperty()
The node placed on the left edge of this border pane.
|
<any> |
rightProperty()
The node placed on the right edge of this border pane.
|
static void |
setAlignment(Node child,
Pos value)
Sets the alignment for the child when contained by a border pane.
|
void |
setBottom(Node value)
Sets the value of the property bottom.
|
void |
setCenter(Node value)
Sets the value of the property center.
|
void |
setLeft(Node value)
Sets the value of the property left.
|
static void |
setMargin(Node child,
Insets value)
Sets the margin for the child when contained by a border pane.
|
void |
setRight(Node value)
Sets the value of the property right.
|
void |
setTop(Node value)
Sets the value of the property top.
|
<any> |
topProperty()
The node placed on the top edge of this border pane.
|
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, getClassCssMetaData, getCssMetaData, 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> centerProperty
getCenter()
,
setCenter(Node)
public final <any> topProperty
getTop()
,
setTop(Node)
public final <any> bottomProperty
getBottom()
,
setBottom(Node)
public final <any> leftProperty
getLeft()
,
setLeft(Node)
public final <any> rightProperty
getRight()
,
setRight(Node)
private static final java.lang.String MARGIN
private static final java.lang.String ALIGNMENT
private <any> center
private <any> top
private <any> bottom
private <any> left
private <any> right
public BorderPane()
public BorderPane(Node center)
center
- The node to set as the center of the BorderPane.public BorderPane(Node center, Node top, Node right, Node bottom, Node left)
center
- The node to set as the center of the BorderPane.top
- The node to set as the top of the BorderPane.right
- The node to set as the right of the BorderPane.bottom
- The node to set as the bottom of the BorderPane.left
- The node to set as the left of the BorderPane.public static void setAlignment(Node child, Pos value)
child
- the child node of a border panevalue
- the alignment position for the childpublic static Pos getAlignment(Node child)
child
- the child node of a border panepublic static void setMargin(Node child, Insets value)
child
- the child node of a border panevalue
- the margin of space around the childpublic static Insets getMargin(Node child)
child
- the child node of a border paneprivate static Insets getNodeMargin(Node child)
public static void clearConstraints(Node child)
child
- the child nodepublic final <any> centerProperty()
getCenter()
,
setCenter(Node)
public final void setCenter(Node value)
public final Node getCenter()
public final <any> topProperty()
getTop()
,
setTop(Node)
public final void setTop(Node value)
public final Node getTop()
public final <any> bottomProperty()
getBottom()
,
setBottom(Node)
public final void setBottom(Node value)
public final Node getBottom()
public final <any> leftProperty()
getLeft()
,
setLeft(Node)
public final void setLeft(Node value)
public final Node getLeft()
public final <any> rightProperty()
getRight()
,
setRight(Node)
public final void setRight(Node value)
public final Node getRight()
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 height)
Region
computePrefWidth
in class Region
protected double computePrefHeight(double width)
Region
computePrefHeight
in class Region
protected void layoutChildren()
private double getAreaWidth(Node child, double height, boolean minimum)
private double getAreaHeight(Node child, double width, boolean minimum)
private boolean childHasContentBias(Node child, Orientation orientation)