BorderPane lays out children in top, left, right, bottom, and center positions.
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 childrens' 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);
extends