Class GridPane
- All Implemented Interfaces:
LayoutMeasurable
,LayoutMeasurableMixin
,HasBackgroundProperty
,HasBlendModeProperty
,HasBorderProperty
,HasClipProperty
,HasEffectProperty
,HasHeightProperty
,HasLayoutXProperty
,HasLayoutYProperty
,HasManagedProperty
,HasMaxHeightProperty
,HasMaxWidthProperty
,HasMinHeightProperty
,HasMinWidthProperty
,HasMouseTransparentProperty
,HasOnMouseClickedProperty
,HasOpacityProperty
,HasPaddingProperty
,HasParentProperty
,HasPrefHeightProperty
,HasPrefWidthProperty
,HasSnapToPixelProperty
,HasVisibleProperty
,HasWidthProperty
,Styleable
,EventTarget
,INode
,PreferenceResizableNode
A child may be placed anywhere within the grid and may span multiple rows/columns. Children may freely overlap within rows/columns and their stacking order will be defined by the order of the gridpane's children list (0th node in back, last node in front).
GridPane may be styled with backgrounds and borders using CSS. See
Region
superclass for details.
Grid Constraints
A child's placement within the grid is defined by it's layout constraints:
Constraint | Type | Description |
---|---|---|
columnIndex | integer | column where child's layout area starts. |
rowIndex | integer | row where child's layout area starts. |
columnSpan | integer | the number of columns the child's layout area spans horizontally. |
rowSpan | integer | the number of rows the child's layout area spans vertically. |
If the row/column indices are not explicitly set, then the child will be placed in the first row/column. If row/column spans are not set, they will default to 1. A child's placement constraints can be changed dynamically and the gridpane will update accordingly.
The total number of rows/columns does not need to be specified up front as the gridpane will automatically expand/contract the grid to accommodate the content.
To use the GridPane, an application needs to set the layout constraints on the children and add those children to the gridpane instance. Constraints are set on the children using static setter methods on the GridPane class:
GridPane gridpane = new GridPane();
// Set one constraint at a time...
// Places the button at the first row and second column
Button button = new Button();
GridPane.setRowIndex(button, 0);
GridPane.setColumnIndex(button, 1);
// or convenience methods set more than one constraint at once...
Label label = new Label();
GridPane.setConstraints(label, 2, 0); // column=2 row=0
// don't forget to add children to gridpane
gridpane.getChildren().addAll(button, label);
Applications may also use convenience methods which combine the steps of
setting the constraints and adding the children:
GridPane gridpane = new GridPane();
gridpane.add(new Button(), 1, 0); // column=1 row=0
gridpane.add(new Label(), 2, 0); // column=2 row=0
Row/Column Sizing
By default, rows and columns will be sized to fit their content; a column will be wide enough to accommodate the widest child, a row tall enough to fit the tallest child.However, if an application needs to explicitly control the size of rows or columns, it may do so by adding RowConstraints and ColumnConstraints objects to specify those metrics. For example, to create a grid with two fixed-width columns:
GridPane gridpane = new GridPane();
gridpane.getColumnConstraints().add(new ColumnConstraints(100)); // column 0 is 100 wide
gridpane.getColumnConstraints().add(new ColumnConstraints(200)); // column 1 is 200 wide
By default the gridpane will resize rows/columns to their preferred sizes (either
computed from content or fixed), even if the gridpane is resized larger than
its preferred size. If an application needs a particular row or column to
grow if there is extra space, it may set its grow priority on the RowConstraints
or ColumnConstraints object. For example:
GridPane gridpane = new GridPane();
ColumnConstraints column1 = new ColumnConstraints(100,100,Double.MAX_VALUE);
column1.setHgrow(Priority.ALWAYS);
ColumnConstraints column2 = new ColumnConstraints(100);
gridpane.getColumnConstraints().addAll(column1, column2); // first column gets any extra width
Note: Nodes spanning multiple rows/columns will be also size to the preferred sizes. The affected rows/columns are resized by the following priority: grow priorities, last row. This is with respect to row/column constraints.
Percentage Sizing
Alternatively, RowConstraints and ColumnConstraints allow the size to be specified as a percentage of gridpane's available space:
GridPane gridpane = new GridPane();
ColumnConstraints column1 = new ColumnConstraints();
column1.setPercentWidth(50);
ColumnConstraints column2 = new ColumnConstraints();
column2.setPercentWidth(50);
gridpane.getColumnConstraints().addAll(column1, column2); // each get 50% of width
If a percentage value is set on a row/column, then that value takes precedent and the
row/column's min, pref, max, and grow constraints will be ignored.
Note that if the sum of the widthPercent (or heightPercent) values total greater than 100, the values will be treated as weights. e.g. if 3 columns are each given a widthPercent of 50, then each will be allocated 1/3 of the gridpane's available width (50/(50+50+50)).
Mixing Size Types
An application may freely mix the size-types of rows/columns (computed from content, fixed, or percentage). The percentage rows/columns will always be allocated space first based on their percentage of the gridpane's available space (size minus insets and gaps). The remaining space will be allocated to rows/columns given their minimum, preferred, and maximum sizes and grow priorities.Resizable Range
A gridpane's parent will resize the gridpane within the gridpane's resizable range during layout. By default the gridpane computes this range based on its content and row/column constraints as outlined in the table below.
width | height | |
---|---|---|
minimum | left/right insets plus the sum of each column's min width. | top/bottom insets plus the sum of each row's min height. |
preferred | left/right insets plus the sum of each column's pref width. | top/bottom insets plus the sum of each row's pref height. |
maximum | Double.MAX_VALUE | Double.MAX_VALUE |
A gridpane'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.
GridPane provides properties for setting the size range directly. These properties default to the sentinel value USE_COMPUTED_SIZE, however the application may set them to other values as needed:
gridpane.setPrefSize(300, 300);
// never size the gridpane larger than its preferred size:
gridpane.setMaxSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
Applications may restore the computed values by setting these properties back
to USE_COMPUTED_SIZE.
GridPane 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.
Optional Layout Constraints
An application may set additional constraints on children to customize how the child is sized and positioned within the layout area established by it's row/column indices/spans:
Constraint | Type | Description |
---|---|---|
halignment | javafx.geometry.HPos | The horizontal alignment of the child within its layout area. |
valignment | javafx.geometry.VPos | The vertical alignment of the child within its layout area. |
hgrow | javafx.scene.layout.Priority | The horizontal grow priority of the child. |
vgrow | javafx.scene.layout.Priority | The vertical grow priority of the child. |
margin | javafx.geometry.Insets | Margin space around the outside of the child. |
By default the alignment of a child within its layout area is defined by the alignment set for the row and column. If an individual alignment constraint is set on a child, that alignment will override the row/column alignment only for that child. Alignment of other children in the same row or column will not be affected.
Grow priorities, on the other hand, can only be applied to entire rows or columns. Therefore, if a grow priority constraint is set on a single child, it will be used to compute the default grow priority of the encompassing row/column. If a grow priority is set directly on a RowConstraint or ColumnConstraint object, it will override the value computed from content.
- Since:
- JavaFX 2.0
-
Property Summary
TypePropertyDescriptionfinal ObjectProperty<Pos>
The alignment of of the grid within the gridpane's width and height.For debug purposes only: controls whether lines are displayed to show the gridpane's rows and columns.final DoubleProperty
The width of the horizontal gaps between columns.final DoubleProperty
The height of the vertical gaps between rows.Properties inherited from class javafx.scene.layout.Region
background, border, height, insets, maxHeight, maxWidth, minHeight, minWidth, padding, prefHeight, prefWidth, snapToPixel, width
Properties inherited from class javafx.scene.Parent
needsLayout
Properties inherited from class javafx.scene.Node
blendMode, cacheHint, cache, clip, cursor, disabled, disable, effect, eventDispatcher, focused, focusTraversable, hover, id, layoutBounds, layoutX, layoutY, managed, mouseTransparent, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragged, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onScroll, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, opacity, parent, pressed, rotate, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, visible
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasBlendModeProperty
blendMode
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasClipProperty
clip
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasEffectProperty
effect
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasLayoutXProperty
layoutX
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasLayoutYProperty
layoutY
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasManagedProperty
managed
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMouseTransparentProperty
mouseTransparent
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasOnMouseClickedProperty
onMouseClicked
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasOpacityProperty
opacity
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasParentProperty
parent
Properties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasVisibleProperty
visible
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Sentinel value which may be set on a child's row/column span constraint to indicate that it should span the remaining rows/columns.Fields inherited from interface javafx.scene.INode
BASELINE_OFFSET_SAME_AS_HEIGHT
Fields inherited from interface javafx.scene.layout.PreferenceResizableNode
USE_COMPUTED_SIZE, USE_PREF_SIZE
-
Constructor Summary
ConstructorDescriptionGridPane()
Creates a GridPane layout with hgap/vgap = 0 and TOP_LEFT alignment. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a child to the gridpane at the specified column,row position.void
Adds a child to the gridpane at the specified column,row position and spans.void
Convenience method for placing the specified nodes sequentially in a given column of the gridpane.void
Convenience method for placing the specified nodes sequentially in a given row of the gridpane.final ObjectProperty<Pos>
The alignment of of the grid within the gridpane's width and height.static void
clearConstraints
(Node child) Removes all gridpane 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.final Pos
Gets the value of thealignment
property.final ObservableList<ColumnConstraints>
Returns list of column constraints.final int
Returns the number of columns in this GridPane.static Integer
getColumnIndex
(Node child) Returns the child's column index constraint if set.static Integer
getColumnSpan
(Node child) Returns the child's column-span constraint if set.static HPos
getHalignment
(Node child) Returns the child's halignment constraint if set.final double
getHgap()
Gets the value of thehgap
property.static Priority
Returns the child's hgrow constraint if set.static Insets
Returns the child's margin constraint if set.final ObservableList<RowConstraints>
Returns list of row constraints.final int
Returns the number of rows in this GridPane.static Integer
getRowIndex
(Node child) Returns the child's row index constraint if set.static Integer
getRowSpan
(Node child) Returns the child's row-span constraint if set.static VPos
getValignment
(Node child) Returns the child's valignment constraint if set.final double
getVgap()
Gets the value of thevgap
property.static Priority
Returns the child's vgrow constraint if set.For debug purposes only: controls whether lines are displayed to show the gridpane's rows and columns.final DoubleProperty
The width of the horizontal gaps between columns.static Boolean
isFillHeight
(Node child) Returns the child's vertical fill policy if setstatic Boolean
isFillWidth
(Node child) Returns the child's horizontal fill policy if setfinal boolean
protected void
Invoked during the layout pass to layout the children in thisParent
.void
Requests a layout pass to be performed before the next scene is rendered.final void
setAlignment
(Pos value) Sets the value of thealignment
property.static void
setColumnIndex
(Node child, Integer value) Sets the column index for the child when contained by a gridpane so that it will be positioned starting in that column of the gridpane.static void
setColumnSpan
(Node child, Integer value) Sets the column span for the child when contained by a gridpane so that it will span that number of columns horizontally.static void
setConstraints
(Node child, int columnIndex, int rowIndex) Sets the column,row indeces for the child when contained in a gridpane.static void
setConstraints
(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan) Sets the column, row, column-span, and row-span value for the child when contained in a gridpane.static void
setConstraints
(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan, HPos halignment, VPos valignment) Sets the grid position, spans, and alignment for the child when contained in a gridpane.static void
setConstraints
(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan, HPos halignment, VPos valignment, Priority hgrow, Priority vgrow) Sets the grid position, spans, and alignment for the child when contained in a gridpane.static void
setConstraints
(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan, HPos halignment, VPos valignment, Priority hgrow, Priority vgrow, Insets margin) Sets the grid position, spans, alignment, grow priorities, and margin for the child when contained in a gridpane.static void
setFillHeight
(Node child, Boolean value) Sets the vertical fill policy for the child when contained by a gridpane.static void
setFillWidth
(Node child, Boolean value) Sets the horizontal fill policy for the child when contained by a gridpane.final void
setGridLinesVisible
(boolean value) Sets the value of thegridLinesVisible
property.static void
setHalignment
(Node child, HPos value) Sets the horizontal alignment for the child when contained by a gridpane.final void
setHgap
(double value) Sets the value of thehgap
property.static void
Sets the horizontal grow priority for the child when contained by a gridpane.static void
Sets the margin for the child when contained by a gridpane.static void
setRowIndex
(Node child, Integer value) Sets the row index for the child when contained by a gridpane so that it will be positioned starting in that row of the gridpane.static void
setRowSpan
(Node child, Integer value) Sets the row span for the child when contained by a gridpane so that it will span that number of rows vertically.static void
setValignment
(Node child, VPos value) Sets the vertical alignment for the child when contained by a gridpane.final void
setVgap
(double value) Sets the value of thevgap
property.static void
Sets the vertical grow priority for the child when contained by a gridpane.toString()
Returns a string representation of thisGridPane
object.final DoubleProperty
The height of the vertical gaps between rows.Methods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, boundedSize, computeMaxHeight, computeMaxWidth, getInsets, heightProperty, impl_computeGeomBounds, impl_computeLayoutBounds, impl_maxHeight, impl_maxWidth, impl_minHeight, impl_minWidth, impl_prefHeight, impl_prefWidth, insetsProperty, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeightProperty, maxWidthProperty, minHeightProperty, minWidthProperty, paddingProperty, positionInArea, positionInArea, prefHeightProperty, prefWidthProperty, resize, setMaxSize, setMinSize, setPrefSize, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
Methods inherited from class javafx.scene.Parent
getBaselineOffset, getChildren, getChildrenUnmodifiable, getManagedChildren, isNeedsLayout, layout, needsLayoutProperty, requestParentLayout, setLayoutFlag, setNeedsLayout, setSceneRoot
Methods inherited from class javafx.scene.Node
addEventFilter, addEventHandler, autosize, blendModeProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, createLayoutMeasurable, cursorProperty, disabledProperty, disableProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAllNodeTransforms, getBoundsInLocal, getCacheHint, getCursor, getEventDispatcher, getId, getLayoutMeasurable, getNodePeer, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseDragged, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnScroll, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOrCreateAndBindNodePeer, getProperties, getRotate, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleClass, getTransforms, getTranslateX, getTranslateY, getUserData, hasProperties, hoverProperty, idProperty, impl_getLayoutBounds, impl_isTreeVisible, impl_traverse, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isPressed, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToScene, localToScene, localToScreen, localToScreen, localToScreen, localToScreen, managedProperty, mouseTransparentProperty, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDraggedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onNodePeerReady, onPeerSizeChanged, onScrollProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, opacityProperty, parentProperty, parentToLocal, pressedProperty, removeEventFilter, removeEventHandler, requestFocus, requestPeerFocus, rotateProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, setCache, setCacheHint, setCursor, setDisable, setDisabled, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setNodePeer, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseDragged, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnScroll, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setPressed, setRotate, setScaleX, setScaleY, setScaleZ, setScene, setStyle, setTranslateX, setTranslateY, setUserData, shouldUseLayoutMeasurable, snapshot, startDragAndDrop, styleProperty, toBack, toFront, translateXProperty, translateYProperty, visibleProperty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasBackgroundProperty
getBackground, setBackground
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasBlendModeProperty
blendModeProperty, getBlendMode, setBlendMode
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasBorderProperty
getBorder, setBorder
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasClipProperty
clipProperty, getClip, setClip
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasEffectProperty
effectProperty, getEffect, setEffect
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasHeightProperty
getHeight, setHeight
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasLayoutXProperty
getLayoutX, layoutXProperty, setLayoutX
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasLayoutYProperty
getLayoutY, layoutYProperty, setLayoutY
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasManagedProperty
isManaged, managedProperty, setManaged
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMaxHeightProperty
getMaxHeight, setMaxHeight
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMaxWidthProperty
getMaxWidth, setMaxWidth
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMinHeightProperty
getMinHeight, setMinHeight
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMinWidthProperty
getMinWidth, setMinWidth
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMouseTransparentProperty
isMouseTransparent, mouseTransparentProperty, setMouseTransparent
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasOnMouseClickedProperty
getOnMouseClicked, onMouseClickedProperty, setOnMouseClicked
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasOpacityProperty
getOpacity, opacityProperty, setOpacity
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasPaddingProperty
getPadding, setPadding
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasParentProperty
getParent, parentProperty, setParent
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasPrefHeightProperty
getPrefHeight, setPrefHeight
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasPrefWidthProperty
getPrefWidth, setPrefWidth
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasSnapToPixelProperty
isSnapToPixel, setSnapToPixel
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasVisibleProperty
isVisible, setVisible, visibleProperty
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasWidthProperty
getWidth, setWidth
Methods inherited from interface javafx.scene.INode
autosize, getAllNodeTransforms, getBaselineOffset, getNodePeer, getOrCreateAndBindNodePeer, getProperties, getScene, getTransforms, hasProperties, relocate, resizeRelocate
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.emul_coupling.LayoutMeasurableMixin
clearCache, getLayoutBounds, getLayoutMeasurable, maxHeight, maxWidth, minHeight, minWidth, prefHeight, prefWidth
Methods inherited from interface javafx.scene.layout.PreferenceResizableNode
isResizable
-
Property Details
-
hgap
The width of the horizontal gaps between columns.- See Also:
-
vgap
The height of the vertical gaps between rows.- See Also:
-
alignment
The alignment of of the grid within the gridpane's width and height. -
gridLinesVisible
For debug purposes only: controls whether lines are displayed to show the gridpane's rows and columns. Default isfalse
.
-
-
Field Details
-
REMAINING
public static final int REMAININGSentinel value which may be set on a child's row/column span constraint to indicate that it should span the remaining rows/columns.- See Also:
-
-
Constructor Details
-
GridPane
public GridPane()Creates a GridPane layout with hgap/vgap = 0 and TOP_LEFT alignment.
-
-
Method Details
-
setRowIndex
Sets the row index for the child when contained by a gridpane so that it will be positioned starting in that row of the gridpane. If a gridpane child has no row index set, it will be positioned in the first row. Setting the value to null will remove the constraint.- Parameters:
child
- the child node of a gridpanevalue
- the row index of the child
-
getRowIndex
Returns the child's row index constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the row index for the child or null if no row index was set
-
setColumnIndex
Sets the column index for the child when contained by a gridpane so that it will be positioned starting in that column of the gridpane. If a gridpane child has no column index set, it will be positioned in the first column. Setting the value to null will remove the constraint.- Parameters:
child
- the child node of a gridpanevalue
- the column index of the child
-
getColumnIndex
Returns the child's column index constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the column index for the child or null if no column index was set
-
setRowSpan
Sets the row span for the child when contained by a gridpane so that it will span that number of rows vertically. This may be set to REMAINING, which will cause the span to extend across all the remaining rows.If a gridpane child has no row span set, it will default to spanning one row. Setting the value to null will remove the constraint.
- Parameters:
child
- the child node of a gridpanevalue
- the row span of the child
-
getRowSpan
Returns the child's row-span constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the row span for the child or null if no row span was set
-
setColumnSpan
Sets the column span for the child when contained by a gridpane so that it will span that number of columns horizontally. This may be set to REMAINING, which will cause the span to extend across all the remaining columns.If a gridpane child has no column span set, it will default to spanning one column. Setting the value to null will remove the constraint.
- Parameters:
child
- the child node of a gridpanevalue
- the column span of the child
-
getColumnSpan
Returns the child's column-span constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the column span for the child or null if no column span was set
-
setMargin
Sets the margin for the child when contained by a gridpane. If set, the gridpane will lay it out with the margin space around it. Setting the value to null will remove the constraint.- Parameters:
child
- the child node of a gridpanevalue
- the margin of space around the child
-
getMargin
Returns the child's margin constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the margin for the child or null if no margin was set
-
setHalignment
Sets the horizontal alignment for the child when contained by a gridpane. If set, will override the gridpane's default horizontal alignment. Setting the value to null will remove the constraint.- Parameters:
child
- the child node of a gridpanevalue
- the hozizontal alignment for the child
-
getHalignment
Returns the child's halignment constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the horizontal alignment for the child or null if no alignment was set
-
setValignment
Sets the vertical alignment for the child when contained by a gridpane. If set, will override the gridpane's default vertical alignment. Setting the value to null will remove the constraint.- Parameters:
child
- the child node of a gridpanevalue
- the vertical alignment for the child
-
getValignment
Returns the child's valignment constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the vertical alignment for the child or null if no alignment was set
-
setHgrow
Sets the horizontal grow priority for the child when contained by a gridpane. If set, the gridpane will use the priority to allocate the child additional horizontal space if the gridpane is resized larger than it's preferred width. Setting the value to null will remove the constraint.- Parameters:
child
- the child of a gridpanevalue
- the horizontal grow priority for the child
-
getHgrow
Returns the child's hgrow constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the horizontal grow priority for the child or null if no priority was set
-
setVgrow
Sets the vertical grow priority for the child when contained by a gridpane. If set, the gridpane will use the priority to allocate the child additional vertical space if the gridpane is resized larger than it's preferred height. Setting the value to null will remove the constraint.- Parameters:
child
- the child of a gridpanevalue
- the vertical grow priority for the child
-
getVgrow
Returns the child's vgrow constraint if set.- Parameters:
child
- the child node of a gridpane- Returns:
- the vertical grow priority for the child or null if no priority was set
-
setFillWidth
Sets the horizontal fill policy for the child when contained by a gridpane. If set, the gridpane will use the policy to determine whether node should be expanded to fill the column or resized to its preferred width. Setting the value to null will remove the constraint. If not value is specified for the node nor for the column, the default value is true.- Parameters:
child
- the child node of a gridpanevalue
- the horizontal fill policy or null for unset- Since:
- JavaFX 8.0
-
isFillWidth
Returns the child's horizontal fill policy if set- Parameters:
child
- the child node of a gridpane- Returns:
- the horizontal fill policy for the child or null if no policy was set
- Since:
- JavaFX 8.0
-
setFillHeight
Sets the vertical fill policy for the child when contained by a gridpane. If set, the gridpane will use the policy to determine whether node should be expanded to fill the row or resized to its preferred height. Setting the value to null will remove the constraint. If not value is specified for the node nor for the row, the default value is true.- Parameters:
child
- the child node of a gridpanevalue
- the vertical fill policy or null for unset- Since:
- JavaFX 8.0
-
isFillHeight
Returns the child's vertical fill policy if set- Parameters:
child
- the child node of a gridpane- Returns:
- the vertical fill policy for the child or null if no policy was set
- Since:
- JavaFX 8.0
-
setConstraints
Sets the column,row indeces for the child when contained in a gridpane.- Parameters:
child
- the child node of a gridpanecolumnIndex
- the column index position for the childrowIndex
- the row index position for the child
-
setConstraints
public static void setConstraints(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan) Sets the column, row, column-span, and row-span value for the child when contained in a gridpane.- Parameters:
child
- the child node of a gridpanecolumnIndex
- the column index position for the childrowIndex
- the row index position for the childcolumnspan
- the number of columns the child should spanrowspan
- the number of rows the child should span
-
setConstraints
public static void setConstraints(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan, HPos halignment, VPos valignment) Sets the grid position, spans, and alignment for the child when contained in a gridpane.- Parameters:
child
- the child node of a gridpanecolumnIndex
- the column index position for the childrowIndex
- the row index position for the childcolumnspan
- the number of columns the child should spanrowspan
- the number of rows the child should spanhalignment
- the horizontal alignment of the childvalignment
- the vertical alignment of the child
-
setConstraints
public static void setConstraints(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan, HPos halignment, VPos valignment, Priority hgrow, Priority vgrow) Sets the grid position, spans, and alignment for the child when contained in a gridpane.- Parameters:
child
- the child node of a gridpanecolumnIndex
- the column index position for the childrowIndex
- the row index position for the childcolumnspan
- the number of columns the child should spanrowspan
- the number of rows the child should spanhalignment
- the horizontal alignment of the childvalignment
- the vertical alignment of the childhgrow
- the horizontal grow priority of the childvgrow
- the vertical grow priority of the child
-
setConstraints
public static void setConstraints(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan, HPos halignment, VPos valignment, Priority hgrow, Priority vgrow, Insets margin) Sets the grid position, spans, alignment, grow priorities, and margin for the child when contained in a gridpane.- Parameters:
child
- the child node of a gridpanecolumnIndex
- the column index position for the childrowIndex
- the row index position for the childcolumnspan
- the number of columns the child should spanrowspan
- the number of rows the child should spanhalignment
- the horizontal alignment of the childvalignment
- the vertical alignment of the childhgrow
- the horizontal grow priority of the childvgrow
- the vertical grow priority of the childmargin
- the margin of space around the child
-
clearConstraints
Removes all gridpane constraints from the child node.- Parameters:
child
- the child node
-
hgapProperty
The width of the horizontal gaps between columns.- Returns:
- the
hgap
property - See Also:
-
setHgap
public final void setHgap(double value) Sets the value of thehgap
property.- Property description:
- The width of the horizontal gaps between columns.
- Parameters:
value
- the value for thehgap
property- See Also:
-
getHgap
public final double getHgap()Gets the value of thehgap
property.- Property description:
- The width of the horizontal gaps between columns.
- Returns:
- the value of the
hgap
property - See Also:
-
vgapProperty
The height of the vertical gaps between rows.- Returns:
- the
vgap
property - See Also:
-
setVgap
public final void setVgap(double value) Sets the value of thevgap
property.- Property description:
- The height of the vertical gaps between rows.
- Parameters:
value
- the value for thevgap
property- See Also:
-
getVgap
public final double getVgap()Gets the value of thevgap
property.- Property description:
- The height of the vertical gaps between rows.
- Returns:
- the value of the
vgap
property - See Also:
-
alignmentProperty
The alignment of of the grid within the gridpane's width and height.- Returns:
- the
alignment
property - See Also:
-
setAlignment
Sets the value of thealignment
property.- Property description:
- The alignment of of the grid within the gridpane's width and height.
- Parameters:
value
- the value for thealignment
property- See Also:
-
getAlignment
Gets the value of thealignment
property.- Property description:
- The alignment of of the grid within the gridpane's width and height.
- Returns:
- the value of the
alignment
property - See Also:
-
gridLinesVisibleProperty
For debug purposes only: controls whether lines are displayed to show the gridpane's rows and columns. Default isfalse
.- Returns:
- the
gridLinesVisible
property - See Also:
-
setGridLinesVisible
public final void setGridLinesVisible(boolean value) Sets the value of thegridLinesVisible
property.- Property description:
- For debug purposes only: controls whether lines are displayed to show the gridpane's rows and columns.
Default is
false
. - Parameters:
value
- the value for thegridLinesVisible
property- See Also:
-
isGridLinesVisible
public final boolean isGridLinesVisible() -
getRowConstraints
Returns list of row constraints. Row constraints can be added to explicitly control individual row sizing and layout behavior. If not set, row sizing and layout behavior is computed based on content. Index in the ObservableList denotes the row number, so the row constraint for the first row is at the position of 0. -
getColumnConstraints
Returns list of column constraints. Column constraints can be added to explicitly control individual column sizing and layout behavior. If not set, column sizing and layout behavior is computed based on content. Index in the ObservableList denotes the column number, so the column constraint for the first column is at the position of 0. -
add
Adds a child to the gridpane at the specified column,row position. This convenience method will set the gridpane column and row constraints on the child.- Parameters:
child
- the node being added to the gridpanecolumnIndex
- the column index position for the child within the gridpane, counting from 0rowIndex
- the row index position for the child within the gridpane, counting from 0
-
add
Adds a child to the gridpane at the specified column,row position and spans. This convenience method will set the gridpane column, row, and span constraints on the child.- Parameters:
child
- the node being added to the gridpanecolumnIndex
- the column index position for the child within the gridpane, counting from 0rowIndex
- the row index position for the child within the gridpane, counting from 0colspan
- the number of columns the child's layout area should spanrowspan
- the number of rows the child's layout area should span
-
addRow
Convenience method for placing the specified nodes sequentially in a given row of the gridpane. If the row already contains nodes the specified nodes will be appended to the row. For example, the first node will be positioned at [column,row], the second at [column+1,row], etc. This method will set the appropriate gridpane row/column constraints on the nodes as well as add the nodes to the gridpane's children sequence.- Parameters:
rowIndex
- the row index position for the children within the gridpanechildren
- the nodes to be added as a row in the gridpane
-
addColumn
Convenience method for placing the specified nodes sequentially in a given column of the gridpane. If the column already contains nodes the specified nodes will be appended to the column. For example, the first node will be positioned at [column, row], the second at [column, row+1], etc. This method will set the appropriate gridpane row/column constraints on the nodes as well as add the nodes to the gridpane's children sequence.- Parameters:
columnIndex
- the column index position for the children within the gridpanechildren
- the nodes to be added as a column in the gridpane
-
computeMinWidth
protected double computeMinWidth(double height) Description copied from class:Region
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.- Overrides:
computeMinWidth
in classRegion
- Parameters:
height
- the height that should be used if min width depends on it- Returns:
- the computed minimum width of this region
-
computeMinHeight
protected double computeMinHeight(double width) Description copied from class:Region
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.- Overrides:
computeMinHeight
in classRegion
- Parameters:
width
- the width that should be used if min height depends on it- Returns:
- the computed minimum height for this region
-
computePrefWidth
protected double computePrefWidth(double height) Description copied from class:Region
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.- Overrides:
computePrefWidth
in classRegion
- Parameters:
height
- the height that should be used if preferred width depends on it- Returns:
- the computed preferred width for this region
-
computePrefHeight
protected double computePrefHeight(double width) Description copied from class:Region
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.- Overrides:
computePrefHeight
in classRegion
- Parameters:
width
- the width that should be used if preferred height depends on it- Returns:
- the computed preferred height for this region
-
getContentBias
- Returns:
- null unless one of its children has a content bias.
-
requestLayout
public void requestLayout()Description copied from class:Parent
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 layout root or unmanaged, then it will be added directly to the scene's dirty layout list, otherwise requestParentLayout will be invoked.
- Overrides:
requestLayout
in classParent
-
layoutChildren
protected void layoutChildren()Description copied from class:Parent
Invoked during the layout pass to layout the children in thisParent
. 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.
- Overrides:
layoutChildren
in classParent
-
toString
Returns a string representation of thisGridPane
object. -
getRowCount
public final int getRowCount()Returns the number of rows in this GridPane.- Returns:
- the row count
- Since:
- 9
-
getColumnCount
public final int getColumnCount()Returns the number of columns in this GridPane.- Returns:
- the column count
- Since:
- 9
-