Every Region has its layout bounds, which are specified to be (0, 0, width, height). A Region might draw outside these bounds. The content area of a Region is the area which is occupied for the layout of its children. This area is, by default, the same as the layout bounds of the Region, but can be modified by either the properties of a border (either with BorderStrokes or BorderImages), and by padding. The padding can be negative, such that the content area of a Region might extend beyond the layout bounds of the Region, but does not affect the layout bounds.
A Region has a Background, and a Border, although either or both of these might be empty. The Background of a Region is made up of zero or more BackgroundFills, and zero or more BackgroundImages. Likewise, the border of a Region is defined by its Border, which is made up of zero or more BorderStrokes and zero or more BorderImages. All BackgroundFills are drawn first, followed by BackgroundImages, BorderStrokes, and finally BorderImages. The content is drawn above all backgrounds and borders. If a BorderImage is present (and loaded all images properly), then no BorderStrokes are actually drawn, although they are considered for computing the position of the content area (see the stroke width property of a BorderStroke). These semantics are in line with the CSS 3 specification. The purpose of these semantics are to allow an application to specify a fallback BorderStroke to be displayed in the case that an ImageStroke fails to download or load.
By default a Region appears as a Rectangle. A BackgroundFill radii might cause the Rectangle to appear rounded.
This affects not only making the visuals look like a rounded rectangle, but it also causes the picking behavior
of the Region to act like a rounded rectangle, such that locations outside the corner radii are ignored. A
Region can be made to use any shape, however, by specifying the shape property. If a shape is specified,
then all BackgroundFills, BackgroundImages, and BorderStrokes will be applied to the shape. BorderImages are
not used for Regions which have a shape specified.
Although the layout bounds of a Region are not influenced by any Border or Background, the content area
insets and the picking area of the Region are. The insets of the Region define the distance
between the edge of the layout bounds and the edge of the content area. For example, if the Region
layout bounds are (x=0, y=0, width=200, height=100), and the insets are (top=10, right=20, bottom=30, left=40),
then the content area bounds will be (x=40, y=10, width=140, height=60). A Region subclass which is laying
out its children should compute and honor these content area bounds.
By default a Region inherits the layout behavior of its superclass, Parent,
which means that it will resize any resizable child nodes to their preferred
size, but will not reposition them. If an application needs more specific
layout behavior, then it should use one of the Region subclasses:
StackPane, HBox, VBox, TilePane, FlowPane,
BorderPane, GridPane, or AnchorPane.
To implement a more custom layout, a Region subclass must override
computePrefWidth, computePrefHeight, and
layoutChildren. Note that layoutChildren is called automatically
by the scene graph while executing a top-down layout pass and it should not be invoked directly by the
region subclass.
Region subclasses which layout their children will position nodes by setting
layoutX/layoutY and do not alter
translateX/translateY, which are reserved for
adjustments and animation.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class | Region.
This class is reused for the min, pref, and max properties since they all performed the same function (to call requestParentLayout). |
| private class | Region.
An implementation for the ShapeProperty. |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private double | _height
Because the height is very often set and very often read but only sometimes listened to, it is beneficial to use the super-lazy pattern property, where we only inflate the property object when heightProperty() is explicitly invoked. |
| private double | |
| private double | |
| private double | |
| private double | |
| private double | |
| private double | |
| private Shape | |
| private boolean | _snapToPixel
I'm using a super-lazy property pattern here, so as to only create the property object when needed for listeners or when being set from CSS, but also making sure that we only call requestParentLayout in the case that the snapToPixel value has actually changed, whether set via the setter or set via the property object. |
| private double | _width
Because the width is very often set and very often read but only sometimes listened to, it is beneficial to use the super-lazy pattern property, where we only inflate the property object when widthProperty() is explicitly invoked. |
| private final ObjectProperty | background
The background of the Region, which is made up of zero or more BackgroundFills, and zero or more BackgroundImages. |
| private final ObjectProperty | border
The border of the Region, which is made up of zero or more BorderStrokes, and zero or more BorderImages. |
| private Bounds | |
| private BooleanProperty | cacheShape
Defines a hint to the system indicating that the Shape used to define the region's background is stable and would benefit from caching. |
| private BooleanProperty | centerShape
Defines whether the shape is centered within the |
| private boolean | |
| private ReadOnlyDoubleWrapper | height
The height of this resizable node. |
| private InvalidationListener | imageChangeListener
At the time that a Background or Border is set on a Region, we inspect any BackgroundImage or BorderImage objects, to see if the Image backing them is background loading and not yet complete, or is animated. |
| private final Region. | insets
The insets of the Region define the distance from the edge of the region (its layout bounds, or (0, 0, width, height)) to the edge of the content area. |
| private double | |
| private double | lastUsedSnapScaleY
Cached snapScale values, used to determine if snapped cached insets values should be invalidated because screen scale has changed. |
| private DoubleProperty | maxHeight
Property for overriding the region's computed maximum height. |
| private DoubleProperty | maxWidth
Property for overriding the region's computed maximum width. |
| private DoubleProperty | minHeight
Property for overriding the region's computed minimum height. |
| private DoubleProperty | minWidth
Property for overriding the region's computed minimum width. |
| private List | |
| private List | |
| private ObjectProperty | |
| private ObjectProperty | padding
The top, right, bottom, and left padding around the region's content. |
| private DoubleProperty | prefHeight
Property for overriding the region's computed preferred height. |
| private DoubleProperty | prefWidth
Property for overriding the region's computed preferred width. |
| private BooleanProperty | scaleShape
Specifies whether the shape, if defined, is scaled to match the size of the Region. |
| private ObjectProperty | shape
When specified, the |
| private double | |
| private double | |
| private double | |
| private double | snappedTopInset
cached results of snapped insets, this are used a lot during layout so makes sense to keep fast access cached copies here. |
| private BooleanProperty | snapToPixel
Defines whether this region adjusts position, spacing, and size values of its children to pixel boundaries. |
| pack-priv static Vec2d | |
| public static final double | USE_COMPUTED_SIZE
Sentinel value which can be passed to a region's
|
| public static final double | USE_PREF_SIZE
Sentinel value which can be passed to a region's
|
| private ReadOnlyDoubleWrapper | width
The width of this resizable node. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static double | |
| private static double | |
| pack-priv void | |
| pack-priv double | |
| pack-priv double | |
| public final ObjectProperty | |
| public final ObjectProperty | |
| pack-priv static Vec2d | Returns: Vec2d object with width(x parameter) and height (y parameter)the node node, double the width of the bounding area where the node is going to be placed areaWidth, double the height of the bounding area where the node is going to be placed areaHeight, boolean if Node should try to fill the area width fillWidth, boolean if Node should try to fill the area height fillHeight, Vec2d Vec2d object for the result or null if new one should be created result)Returns the size of a Node that should be placed in an area of the specified size, bounded in it's min/max size, respecting bias. |
| pack-priv static double | Returns: the size bounded by min, pref, and max.The minimum bound min, double The value to be clamped between the min and max pref, double the maximum bound max)Hides javafx. Computes the value based on the given min and max values. |
| public final BooleanProperty | |
| public final BooleanProperty | |
| private double | |
| pack-priv double | computeChildMaxAreaHeight(Node child, double maxBaselineComplement, Insets margin, double availableWidth, boolean fillWidth)
|
| pack-priv double | computeChildMaxAreaWidth(Node child, double baselineComplement, Insets margin, double availableHeight, boolean fillHeight)
|
| pack-priv double | |
| pack-priv double | computeChildMinAreaHeight(Node child, double minBaselineComplement, Insets margin, double availableWidth, boolean fillWidth)
|
| pack-priv double | |
| pack-priv double | computeChildMinAreaWidth(Node child, double baselineComplement, Insets margin, double availableHeight, boolean fillHeight)
|
| pack-priv double | |
| pack-priv double | computeChildPrefAreaHeight(Node child, double prefBaselineComplement, Insets margin, double availableWidth, boolean fillWidth)
|
| pack-priv double | |
| pack-priv double | computeChildPrefAreaWidth(Node child, double baselineComplement, Insets margin, double availableHeight, boolean fillHeight)
|
| private double | |
| private double | |
| protected double | Returns: the computed maximum height for this regionThe width of the Region, in case this value might dictate
the maximum height width)Computes the maximum height of this region. |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| pack-priv double | |
| protected double | Returns: the computed maximum width for this regionThe height of the Region, in case this value might dictate
the maximum width height)Computes the maximum width for this region. |
| protected double | Returns: the computed minimum height for this regionOverrides javafx. Computes the minimum height of this region. |
| protected double | Returns: the computed minimum width of this regionOverrides javafx. Computes the minimum width of this region. |
| protected double | Returns: the computed preferred height for this regionOverrides javafx. 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 | Returns: the computed preferred width for this regionOverrides javafx. Computes the preferred width of this region for the given height. |
| private BaseBounds | |
| pack-priv static double | |
| pack-priv static double | |
| private boolean | Returns: True if (px, py) is within the stroke, taking into account insets and corner radii.The x position of the point to test px, final double The y position of the point to test py, final double The x1 position of the bounds to test x1, final double The y1 position of the bounds to test y1, final double The x2 position of the bounds to test x2, final double The y2 position of the bounds to test y2, BorderWidths The widths of the stroke on each side widths, boolean Whether the area is filled or is just stroked filled, final Insets The insets to apply to (x1,y1)-(x2,y2) to get the final bounds to test insets, final CornerRadii The corner radii to test with. Must not be null. rad)Basically we will perform two contains tests. |
| private boolean | Returns: True if (px, py) is within the bounds, taking into account insets and corner radii.The x position of the point to test px, final double The y position of the point to test py, final double The x1 position of the bounds to test x1, final double The y1 position of the bounds to test y1, final double The x2 position of the bounds to test x2, final double The y2 position of the bounds to test y2, final Insets The insets to apply to (x1,y1)-(x2,y2) to get the final bounds to test insets, CornerRadii The corner radii to test with. Must not be null. rad)Determines whether the point (px, py) is contained within the the bounds (x1, y1)-(x2, y2), after taking into account the insets and the corner radii. |
| pack-priv static double[] | |
| private boolean | |
| private BaseBounds | doComputeGeomBounds(BaseBounds bounds, BaseTransform tx)
Hides javafx.
|
| private Bounds | doComputeLayoutBounds()
Hides javafx. The layout bounds of this region: |
| private NGNode | |
| private void | |
| private void | doPickNodeLocal(PickRay pickRay, PickResultChooser result)
Hides javafx. Some skins relying on this Note: This method MUST only be called via its accessor method. |
| private void | |
| pack-priv double | |
| pack-priv static double | |
| pack-priv double | |
| pack-priv static double | |
| pack-priv double | |
| pack-priv static double | getAreaBaselineOffset(List<Node>
the children with baseline alignment children, Callback<Node, Insets> their margins (callback) margins, Function<Integer, Double> callback for children widths (can return -1 if no bias is used) positionToWidth, double height of the area to layout in areaHeight, Function<Integer, Boolean> callback to specify children that has fillHeight constraint fillHeight, double minimum complement minComplement, boolean snapToPixel)Returns the baseline offset of provided children, with respect to the minimum complement, computed
by |
| public final Background | |
| private static double | |
| public final Border | |
| public static List | Returns: theCssMetaDataHides javafx. Gets the |
| public List | getCssMetaData()
Overrides javafx. Implements javafx. This method should delegate to |
| public final double | |
| public final Insets | |
| private double | |
| private double | |
| pack-priv static double | |
| public final double | |
| public final double | |
| pack-priv static double | |
| public final double | |
| public final double | |
| private CornerRadii | Returns: the normalized (non-percentage, non-overflowing) radiithe index of the BackgroundFill whose radii will be normalized. i)Returns the normalized absolute radii for the indicated BackgroundFill, taking the current size of the region into account to eliminate any percentage-based measurements and to scale the radii to prevent overflowing the width or height. |
| private CornerRadii | Returns: the normalized (non-percentage, non-overflowing) radiithe index of the BorderStroke whose radii will be normalized. i)Returns the normalized absolute radii for the indicated BorderStroke, taking the current size of the region into account to eliminate any percentage-based measurements and to scale the radii to prevent overflowing the width or height. |
| public final Insets | |
| public final Insets | |
| pack-priv static double | |
| public final double | |
| public final double | |
| public final Shape | |
| pack-priv static double | |
| private double | |
| pack-priv static double | |
| private double | |
| public String | Returns: A string URLAn implementation may specify its own user-agent styles for this Region, and its children, by overriding this method. |
| public final double | |
| private void | |
| public final ReadOnlyDoubleProperty | |
| public final ReadOnlyObjectProperty | |
| public final boolean | |
| public final boolean | |
| public boolean | Returns: whether this node can be resized by its parent during layoutOverrides javafx. Returns |
| public final boolean | |
| public final boolean | |
| protected void | layoutInArea(Node
the child being positioned within this region child, double the horizontal offset of the layout area relative to this region areaX, double the vertical offset of the layout area relative to this region areaY, double the width of the layout area areaWidth, double the height of the layout area areaHeight, double the baseline offset to be used if VPos is BASELINE areaBaselineOffset, HPos the horizontal alignment for the child within the area halignment, VPos the vertical alignment for the child within the area valignment)Utility method which lays out the child within an area of this
region defined by |
| protected void | layoutInArea(Node
the child being positioned within this region child, double the horizontal offset of the layout area relative to this region areaX, double the vertical offset of the layout area relative to this region areaY, double the width of the layout area areaWidth, double the height of the layout area areaHeight, double the baseline offset to be used if VPos is BASELINE areaBaselineOffset, Insets the margin of space to be allocated around the child margin, HPos the horizontal alignment for the child within the area halignment, VPos the vertical alignment for the child within the area valignment)Utility method which lays out the child within an area of this
region defined by |
| protected void | layoutInArea(Node
the child being positioned within this region child, double the horizontal offset of the layout area relative to this region areaX, double the vertical offset of the layout area relative to this region areaY, double the width of the layout area areaWidth, double the height of the layout area areaHeight, double the baseline offset to be used if VPos is BASELINE areaBaselineOffset, Insets the margin of space to be allocated around the child margin, boolean whether or not the child should be resized to fill the area width or kept to its preferred width fillWidth, boolean whether or not the child should e resized to fill the area height or kept to its preferred height fillHeight, HPos the horizontal alignment for the child within the area halignment, VPos the vertical alignment for the child within the area valignment)Utility method which lays out the child within an area of this
region defined by |
| public static void | layoutInArea(Node
the child being positioned within this region child, double the horizontal offset of the layout area relative to this region areaX, double the vertical offset of the layout area relative to this region areaY, double the width of the layout area areaWidth, double the height of the layout area areaHeight, double the baseline offset to be used if VPos is BASELINE areaBaselineOffset, Insets the margin of space to be allocated around the child margin, boolean whether or not the child should be resized to fill the area width or kept to its preferred width fillWidth, boolean whether or not the child should e resized to fill the area height or kept to its preferred height fillHeight, HPos the horizontal alignment for the child within the area halignment, VPos the vertical alignment for the child within the area valignment, boolean whether to snap size and position to pixels isSnapToPixel)Utility method which lays out the child within an area of it's
parent defined by |
| public final double | Returns: the maximum height that this node should be resized to during layoutOverrides javafx. Called during layout to determine the maximum height for this node. |
| public final DoubleProperty | |
| public final double | Returns: the maximum width that this node should be resized to during layoutOverrides javafx. Called during layout to determine the maximum width for this node. |
| public final DoubleProperty | |
| public final double | Returns: the minimum height that this node should be resized to during layoutOverrides javafx. Called during layout to determine the minimum height for this node. |
| public final DoubleProperty | |
| public final double | Returns: the minimum width that this node should be resized to during layoutOverrides javafx. Called during layout to determine the minimum width for this node. |
| public final DoubleProperty | |
| private static CornerRadii | Returns: Normalized radii.The radii. radii, Insets The insets for the associated background or stroke. insets, double The width of the region before insets are applied. width, double The height of the region before insets are applied. height)Return a version of the radii that is not percentage based and is scaled to fit the indicated inset rectangle without overflow. |
| public final ObjectProperty | Returns: the opaque insets propertyDefines the area of the region within which completely opaque pixels are drawn. |
| public final ObjectProperty | |
| private static void | |
| protected void | positionInArea(Node
the child being positioned within this region child, double the horizontal offset of the layout area relative to this region areaX, double the vertical offset of the layout area relative to this region areaY, double the width of the layout area areaWidth, double the height of the layout area areaHeight, double the baseline offset to be used if VPos is BASELINE areaBaselineOffset, HPos the horizontal alignment for the child within the area halignment, VPos the vertical alignment for the child within the area valignment)Utility method which positions the child within an area of this
region defined by |
| public static void | positionInArea(Node
the child being positioned within this region child, double the horizontal offset of the layout area relative to this region areaX, double the vertical offset of the layout area relative to this region areaY, double the width of the layout area areaWidth, double the height of the layout area areaHeight, double the baseline offset to be used if VPos is BASELINE areaBaselineOffset, Insets the margin of space to be allocated around the child margin, HPos the horizontal alignment for the child within the area halignment, VPos the vertical alignment for the child within the area valignment, boolean whether to snap size and position to pixels isSnapToPixel)Utility method which positions the child within an area of this
region defined by |
| public final double | Returns: the preferred height that this node should be resized to during layoutOverrides javafx. Called during layout to determine the preferred height for this node. |
| public final DoubleProperty | |
| public final double | Returns: the preferred width that this node should be resized to during layoutOverrides javafx. Called during layout to determine the preferred width for this node. |
| public final DoubleProperty | |
| pack-priv void | |
| public void | resize(double
the target layout bounds width width, double the target layout bounds height height)Overrides javafx. Invoked by the region's parent during layout to set the region's width and height. |
| public final BooleanProperty | |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| protected void | |
| public final void | |
| public void | setMaxSize(double
the override value for maximum width maxWidth, double the override value for maximum height maxHeight)Convenience method for overriding the region's computed maximum width and height. |
| public final void | |
| public final void | |
| public void | setMinSize(double
the override value for minimum width minWidth, double the override value for minimum height minHeight)Convenience method for overriding the region's computed minimum width and height. |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| public void | setPrefSize(double
the override value for preferred width prefWidth, double the override value for preferred height prefHeight)Convenience method for overriding the region's computed preferred width and height. |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| protected void | |
| private boolean | shapeContains(Shape shape, final double x, final double y, double topOffset, double rightOffset, double bottomOffset, double leftOffset)
Transform x, y in local Region coordinates to local coordinates of scaled/centered shape and check if the shape contains the coordinates. |
| public final ObjectProperty | |
| public final double | Returns: Rounded up insets bottomUtility method to get the bottom inset which includes padding and border inset. |
| public final double | Returns: Rounded up insets leftUtility method to get the left inset which includes padding and border inset. |
| public final double | Returns: Rounded up insets rightUtility method to get the right inset which includes padding and border inset. |
| public final double | Returns: Rounded up insets topUtility method to get the top inset which includes padding and border inset. |
| private double | Returns: value either as passed, or floored or ceiled with scale, based on snapToPixelThe value that needs to be snapped value, boolean Whether to snap to pixel snapToPixel)If snapToPixel is true, then the value is either floored (positive values) or ceiled (negative values) with a scale. |
| pack-priv double | |
| private double | Returns: value either as passed, or floored or ceiled with scale, based on snapToPixelThe value that needs to be snapped value, boolean Whether to snap to pixel snapToPixel)If snapToPixel is true, then the value is either floored (positive values) or ceiled (negative values) with a scale. |
| pack-priv double | |
| private static double | |
| protected double | Returns: value rounded to nearest pixelthe position value to be snapped value)
Deprecated
since 9. replaced by
snapPositionX() and snapPositionY()
If this region's snapToPixel property is false, this method returns the same value, else it tries to return a value rounded to the nearest pixel, but since there is no indication if the value is a vertical or horizontal measurement then it may be snapped to the wrong pixel size metric on screens with different horizontal and vertical scales. |
| private double | Returns: value either as passed in or rounded based on snapToPixelThe value that needs to be snapped value, boolean Whether to snap to pixel snapToPixel)If snapToPixel is true, then the value is rounded using Math.round. |
| public double | Returns: value rounded to nearest pixelthe position value to be snapped value)If this region's snapToPixel property is true, returns a value rounded to the nearest pixel in the horizontal direction, else returns the same value. |
| private double | |
| public double | Returns: value rounded to nearest pixelthe position value to be snapped value)If this region's snapToPixel property is true, returns a value rounded to the nearest pixel in the vertical direction, else returns the same value. |
| private static double | |
| protected double | Returns: value ceiled to nearest pixelthe size value to be snapped value)
Deprecated
since 9. replaced by
snapSizeX() and snapSizeY()
If this region's snapToPixel property is false, this method returns the same value, else it tries to return a value ceiled to the nearest pixel, but since there is no indication if the value is a vertical or horizontal measurement then it may be snapped to the wrong pixel size metric on screens with different horizontal and vertical scales. |
| private double | Returns: value either as passed in or ceil'd based on snapToPixelThe value that needs to be snapped value, boolean Whether to snap to pixel snapToPixel)If snapToPixel is true, then the value is ceil'd using Math.ceil. |
| public double | Returns: value ceiled to nearest pixelthe size value to be snapped value)If this region's snapToPixel property is true, returns a value ceiled to the nearest pixel in the horizontal direction, else returns the same value. |
| private double | |
| public double | Returns: value ceiled to nearest pixelthe size value to be snapped value)If this region's snapToPixel property is true, returns a value ceiled to the nearest pixel in the vertical direction, else returns the same value. |
| private static double | |
| protected double | Returns: value rounded to nearest pixelthe space value to be snapped value)
Deprecated
since 9. replaced by
snapSpaceX() and snapSpaceY()
If this region's snapToPixel property is false, this method returns the same value, else it tries to return a value rounded to the nearest pixel, but since there is no indication if the value is a vertical or horizontal measurement then it may be snapped to the wrong pixel size metric on screens with different horizontal and vertical scales. |
| private double | Returns: value either as passed in or rounded based on snapToPixelThe value that needs to be snapped value, boolean Whether to snap to pixel snapToPixel)If snapToPixel is true, then the value is rounded using Math.round. |
| public double | Returns: value rounded to nearest pixelthe space value to be snapped value)If this region's snapToPixel property is true, returns a value rounded to the nearest pixel in the horizontal direction, else returns the same value. |
| private double | |
| public double | Returns: value rounded to nearest pixelthe space value to be snapped value)If this region's snapToPixel property is true, returns a value rounded to the nearest pixel in the vertical direction, else returns the same value. |
| public final BooleanProperty | |
| private void | |
| private void | validateCorners()
This method validates all CornerRadii objects in both the set of BackgroundFills and BorderStrokes and saves the normalized values into the private fields above. |
| private void | |
| public final ReadOnlyDoubleProperty |