Class GridPane
- All Implemented Interfaces:
-
Styleable,EventTarget
public class GridPane extends Pane
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 children's 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
| Type | Property | Description |
|---|---|---|
final ObjectProperty |
alignment |
The alignment of the grid within the gridpane's width and height. |
final BooleanProperty |
gridLinesVisible |
For debug purposes only: controls whether lines are displayed to show the gridpane's rows and columns. |
final DoubleProperty |
hgap |
The width of the horizontal gaps between columns. |
final DoubleProperty |
vgap |
The height of the vertical gaps between rows. |
Properties declared in class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
Properties declared in class javafx.scene.Parent
needsLayout
Properties declared in class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
static final int |
REMAINING |
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 declared in class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
Fields declared in class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
Constructor Summary
| Constructor | Description |
|---|---|
GridPane() |
Creates a GridPane layout with hgap/vgap = 0 and TOP_LEFT alignment. |
GridPane |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
add |
Adds a child to the gridpane at the specified [column, row] position. |
void |
add |
Adds a child to the gridpane at the specified [column, row] position and spans. |
void |
addColumn |
Convenience method for placing the specified nodes sequentially in a given column of the gridpane. |
void |
addRow |
Convenience method for placing the specified nodes sequentially in a given row of the gridpane. |
final ObjectProperty |
alignmentProperty() |
The alignment of the grid within the gridpane's width and height. |
static void |
clearConstraints |
Removes all gridpane constraints from the child node. |
final Pos |
getAlignment() |
Gets the value of the alignment property. |
final Bounds |
getCellBounds |
Returns the bounds of the cell at the specified column and row position. |
static List |
getClassCssMetaData() |
Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses. |
final ObservableList |
getColumnConstraints() |
Returns list of column constraints. |
final int |
getColumnCount() |
Returns the number of columns in this GridPane. |
static Integer |
getColumnIndex |
Returns the child's column index constraint if set. |
static Integer |
getColumnSpan |
Returns the child's column-span constraint if set. |
Orientation |
getContentBias() |
Returns the orientation of a node's resizing bias for layout purposes. |
List |
getCssMetaData() |
This method should delegate to Node.getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection. |
static HPos |
getHalignment |
Returns the child's halignment constraint if set. |
final double |
getHgap() |
Gets the value of the hgap property. |
static Priority |
getHgrow |
Returns the child's hgrow constraint if set. |
static Insets |
getMargin |
Returns the child's margin constraint if set. |
final ObservableList |
getRowConstraints() |
Returns list of row constraints. |
final int |
getRowCount() |
Returns the number of rows in this GridPane. |
static Integer |
getRowIndex |
Returns the child's row index constraint if set. |
static Integer |
getRowSpan |
Returns the child's row-span constraint if set. |
static VPos |
getValignment |
Returns the child's valignment constraint if set. |
final double |
getVgap() |
Gets the value of the vgap property. |
static Priority |
getVgrow |
Returns the child's vgrow constraint if set. |
final BooleanProperty |
gridLinesVisibleProperty() |
For debug purposes only: controls whether lines are displayed to show the gridpane's rows and columns. |
final DoubleProperty |
hgapProperty() |
The width of the horizontal gaps between columns. |
static Boolean |
isFillHeight |
Returns the child's vertical fill policy if set |
static Boolean |
isFillWidth |
Returns the child's horizontal fill policy if set |
final boolean |
isGridLinesVisible() |
Gets the value of the gridLinesVisible property. |
final void |
setAlignment |
Sets the value of the alignment property. |
static void |
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. |
static void |
setColumnSpan |
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 |
Sets the column,row indices for the child when contained in a gridpane. |
static void |
setConstraints |
Sets the column, row, column-span, and row-span value for the child when contained in a gridpane. |
static void |
setConstraints |
Sets the grid position, spans, and alignment for the child when contained in a gridpane. |
static void |
setConstraints |
Sets the grid position, spans, and alignment for the child when contained in a gridpane. |
static void |
setConstraints |
Sets the grid position, spans, alignment, grow priorities, and margin for the child when contained in a gridpane. |
static void |
setFillHeight |
Sets the vertical fill policy for the child when contained by a gridpane. |
static void |
setFillWidth |
Sets the horizontal fill policy for the child when contained by a gridpane. |
final void |
setGridLinesVisible |
Sets the value of the gridLinesVisible property. |
static void |
setHalignment |
Sets the horizontal alignment for the child when contained by a gridpane. |
final void |
setHgap |
Sets the value of the hgap property. |
static void |
setHgrow |
Sets the horizontal grow priority for the child when contained by a gridpane. |
static void |
setMargin |
Sets the margin for the child when contained by a gridpane. |
static void |
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. |
static void |
setRowSpan |
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 |
Sets the vertical alignment for the child when contained by a gridpane. |
final void |
setVgap |
Sets the value of the vgap property. |
static void |
setVgrow |
Sets the vertical grow priority for the child when contained by a gridpane. |
String |
toString() |
Returns a string representation of this GridPane object. |
final DoubleProperty |
vgapProperty() |
The height of the vertical gaps between rows. |
Methods declared in class javafx.scene.layout.Pane
getChildren
Methods declared in class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, 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, 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, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
Methods declared in class javafx.scene.Parent
getBaselineOffset, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, layoutChildren, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
Methods declared in class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookup, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, queryAccessibleAttribute, relocate, removeEventFilter, removeEventHandler, requestFocus, requestFocusTraversal, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods declared in interface javafx.css.Styleable
getStyleableNode
Property Details
hgap
public final DoubleProperty hgapProperty
- See Also:
vgap
public final DoubleProperty vgapProperty
- See Also:
alignment
public final ObjectProperty<Pos> alignmentProperty
- See Also:
gridLinesVisible
public final BooleanProperty gridLinesVisibleProperty
false.- See Also:
Field Details
REMAINING
public static final int REMAINING
- See Also:
Constructor Details
GridPane
public GridPane()
GridPane
Method Details
setRowIndex
public static void setRowIndex(Node child, Integer value)
- Parameters:
-
child- the child node of a gridpane -
value- the row index of the child
getRowIndex
public static Integer getRowIndex(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the row index for the child or null if no row index was set
setColumnIndex
public static void setColumnIndex(Node child, Integer value)
- Parameters:
-
child- the child node of a gridpane -
value- the column index of the child
getColumnIndex
public static Integer getColumnIndex(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the column index for the child or null if no column index was set
setRowSpan
public static void setRowSpan(Node child, Integer value)
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 gridpane -
value- the row span of the child
getRowSpan
public static Integer getRowSpan(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the row span for the child or null if no row span was set
setColumnSpan
public static void setColumnSpan(Node child, Integer value)
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 gridpane -
value- the column span of the child
getColumnSpan
public static Integer getColumnSpan(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the column span for the child or null if no column span was set
setMargin
public static void setMargin(Node child, Insets value)
- Parameters:
-
child- the child node of a gridpane -
value- the margin of space around the child
getMargin
public static Insets getMargin(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the margin for the child or null if no margin was set
setHalignment
public static void setHalignment(Node child, HPos value)
- Parameters:
-
child- the child node of a gridpane -
value- the horizontal alignment for the child
getHalignment
public static HPos getHalignment(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the horizontal alignment for the child or null if no alignment was set
setValignment
public static void setValignment(Node child, VPos value)
- Parameters:
-
child- the child node of a gridpane -
value- the vertical alignment for the child
getValignment
public static VPos getValignment(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the vertical alignment for the child or null if no alignment was set
setHgrow
public static void setHgrow(Node child, Priority value)
- Parameters:
-
child- the child of a gridpane -
value- the horizontal grow priority for the child
getHgrow
public static Priority getHgrow(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the horizontal grow priority for the child or null if no priority was set
setVgrow
public static void setVgrow(Node child, Priority value)
- Parameters:
-
child- the child of a gridpane -
value- the vertical grow priority for the child
getVgrow
public static Priority getVgrow(Node child)
- Parameters:
-
child- the child node of a gridpane - Returns:
- the vertical grow priority for the child or null if no priority was set
setFillWidth
public static void setFillWidth(Node child, Boolean value)
- Parameters:
-
child- the child node of a gridpane -
value- the horizontal fill policy or null for unset - Since:
- JavaFX 8.0
isFillWidth
public static Boolean isFillWidth(Node child)
- 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
public static void setFillHeight(Node child, Boolean value)
- Parameters:
-
child- the child node of a gridpane -
value- the vertical fill policy or null for unset - Since:
- JavaFX 8.0
isFillHeight
public static Boolean isFillHeight(Node child)
- 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
public static void setConstraints(Node child, int columnIndex, int rowIndex)
- Parameters:
-
child- the child node of a gridpane -
columnIndex- the column index position for the child -
rowIndex- the row index position for the child
setConstraints
public static void setConstraints(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan)
- Parameters:
-
child- the child node of a gridpane -
columnIndex- the column index position for the child -
rowIndex- the row index position for the child -
columnspan- the number of columns the child should span -
rowspan- 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)
- Parameters:
-
child- the child node of a gridpane -
columnIndex- the column index position for the child -
rowIndex- the row index position for the child -
columnspan- the number of columns the child should span -
rowspan- the number of rows the child should span -
halignment- the horizontal alignment of the child -
valignment- 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)
- Parameters:
-
child- the child node of a gridpane -
columnIndex- the column index position for the child -
rowIndex- the row index position for the child -
columnspan- the number of columns the child should span -
rowspan- the number of rows the child should span -
halignment- the horizontal alignment of the child -
valignment- the vertical alignment of the child -
hgrow- the horizontal grow priority of the child -
vgrow- 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)
- Parameters:
-
child- the child node of a gridpane -
columnIndex- the column index position for the child -
rowIndex- the row index position for the child -
columnspan- the number of columns the child should span -
rowspan- the number of rows the child should span -
halignment- the horizontal alignment of the child -
valignment- the vertical alignment of the child -
hgrow- the horizontal grow priority of the child -
vgrow- the vertical grow priority of the child -
margin- the margin of space around the child
clearConstraints
public static void clearConstraints(Node child)
- Parameters:
-
child- the child node
hgapProperty
public final DoubleProperty hgapProperty()
- Returns:
- the width of the horizontal gaps between columns
- See Also:
setHgap
public final void setHgap(double value)
hgap property.- Property description:
- The width of the horizontal gaps between columns.
- Parameters:
-
value- the value for thehgapproperty - See Also:
getHgap
public final double getHgap()
hgap property.- Property description:
- The width of the horizontal gaps between columns.
- Returns:
- the value of the
hgapproperty - See Also:
vgapProperty
public final DoubleProperty vgapProperty()
- Returns:
- the height of the vertical gaps between rows
- See Also:
setVgap
public final void setVgap(double value)
vgap property.- Property description:
- The height of the vertical gaps between rows.
- Parameters:
-
value- the value for thevgapproperty - See Also:
getVgap
public final double getVgap()
vgap property.- Property description:
- The height of the vertical gaps between rows.
- Returns:
- the value of the
vgapproperty - See Also:
alignmentProperty
public final ObjectProperty<Pos> alignmentProperty()
- Returns:
- the alignment of the grid within the gridpane's width and height
- See Also:
setAlignment
public final void setAlignment(Pos value)
alignment property.- Property description:
- The alignment of the grid within the gridpane's width and height.
- Parameters:
-
value- the value for thealignmentproperty - See Also:
getAlignment
public final Pos getAlignment()
alignment property.- Property description:
- The alignment of the grid within the gridpane's width and height.
- Returns:
- the value of the
alignmentproperty - See Also:
gridLinesVisibleProperty
public final BooleanProperty gridLinesVisibleProperty()
false.- Returns:
- true if lines are displayed to show the gridpane's rows and columns
- See Also:
setGridLinesVisible
public final void setGridLinesVisible(boolean value)
gridLinesVisible 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 thegridLinesVisibleproperty - See Also:
isGridLinesVisible
public final boolean isGridLinesVisible()
gridLinesVisible property.- Property description:
- For debug purposes only: controls whether lines are displayed to show the gridpane's rows and columns. Default is
false. - Returns:
- the value of the
gridLinesVisibleproperty - See Also:
getRowConstraints
public final ObservableList<RowConstraints> getRowConstraints()
- Returns:
- the list of row constraints
getColumnConstraints
public final ObservableList<ColumnConstraints> getColumnConstraints()
- Returns:
- the list of column constraints
add
public void add(Node child, int columnIndex, int rowIndex)
- Parameters:
-
child- the node being added to the gridpane -
columnIndex- the column index position for the child within the gridpane, counting from 0 -
rowIndex- the row index position for the child within the gridpane, counting from 0
add
public void add(Node child, int columnIndex, int rowIndex, int colspan, int rowspan)
- Parameters:
-
child- the node being added to the gridpane -
columnIndex- the column index position for the child within the gridpane, counting from 0 -
rowIndex- the row index position for the child within the gridpane, counting from 0 -
colspan- the number of columns the child's layout area should span -
rowspan- the number of rows the child's layout area should span
addRow
public void addRow(int rowIndex, Node... children)
- Parameters:
-
rowIndex- the row index position for the children within the gridpane -
children- the nodes to be added as a row in the gridpane
addColumn
public void addColumn(int columnIndex, Node... children)
- Parameters:
-
columnIndex- the column index position for the children within the gridpane -
children- the nodes to be added as a column in the gridpane
getContentBias
public Orientation getContentBias()
NodeResizable subclasses should override this method to return an appropriate value.
- Overrides:
-
getContentBiasin classNode - Returns:
- null unless one of its children has a content bias.
- See Also:
toString
getClassCssMetaData
public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
CssMetaData associated with this class, which may include the CssMetaData of its superclasses.- Returns:
- the
CssMetaData - Since:
- JavaFX 8.0
getCssMetaData
public List<CssMetaData<? extends Styleable,?>> getCssMetaData()
Node.getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.- Specified by:
-
getCssMetaDatain interfaceStyleable - Overrides:
-
getCssMetaDatain classRegion - Returns:
- The CssMetaData associated with this node, which may include the CssMetaData of its superclasses.
- Since:
- JavaFX 8.0
getRowCount
public final int getRowCount()
- Returns:
- the row count
- Since:
- 9
getColumnCount
public final int getColumnCount()
- Returns:
- the column count
- Since:
- 9
getCellBounds
public final Bounds getCellBounds(int columnIndex, int rowIndex)
- Parameters:
-
columnIndex- the column index position for the cell within this GridPane, counting from 0 -
rowIndex- the row index position for the cell within this GridPane, counting from 0 - Returns:
- the bounds of the cell at columnIndex and rowIndex.
- Since:
- 9
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.