Top Description Fields Constructors Methods
javafx.scene.layout

public final Class Background

extends Object
implements Interpolatable<Background>
Class Inheritance
All Implemented Interfaces
javafx.animation.Interpolatable
Annotations
@SuppressWarnings:unchecked
Imports
javafx.animation.Interpolatable, javafx.beans.NamedArg, javafx.css.CssMetaData, .Styleable, javafx.geometry.Insets, javafx.scene.Node, javafx.scene.image.Image, javafx.scene.paint.Color, .Paint, java.util.Arrays, .Collections, .List, .Objects, com.sun.javafx.UnmodifiableArrayList, com.sun.javafx.css.SubCssMetaData, javafx.css.converter.InsetsConverter, .PaintConverter, .URLConverter, com.sun.javafx.scene.layout.region.LayeredBackgroundPositionConverter, .LayeredBackgroundSizeConverter, .CornerRadiiConverter, .RepeatStruct, .RepeatStructConverter, com.sun.javafx.tk.Toolkit, com.sun.javafx.util.InterpolationUtils

The Background of a Region. A Background is an immutable object which encapsulates the entire set of data required to render the background of a Region. Because this class is immutable, you can freely reuse the same Background on many different Regions. Please refer to JavaFX CSS Reference Guide for a complete description of the CSS rules for styling the background of a Region.

Every Background is comprised of fills and / or images. Neither list will ever be null, but either or both may be empty. Each defined BackgroundFill is rendered in order, followed by each defined BackgroundImage.

The Background's outsets define any extension of the drawing area of a Region which is necessary to account for all background drawing. These outsets are strictly defined by the BackgroundFills that are specified on this Background, if any, because all BackgroundImages are clipped to the drawing area, and do not define it. The outsets values are strictly non-negative.

Since
JavaFX 8.0

Field Summary

Modifier and TypeField and Description
pack-priv static final CssMetaData<Node, Paint[]>
pack-priv static final CssMetaData<Node, Image[]>
pack-priv static final CssMetaData<Node, Insets[]>
pack-priv static final CssMetaData<Node, BackgroundPosition[]>
pack-priv static final CssMetaData<Node, CornerRadii[]>
pack-priv static final CssMetaData<Node, RepeatStruct[]>
pack-priv static final CssMetaData<Node, BackgroundSize[]>
public static final Background
EMPTY

An empty Background, useful to use instead of null.

private final List<BackgroundFill>
private final int
hash

The cached hash code computation for the Background.

private final boolean
hasOpaqueFill

Specifies whether the Background has at least one opaque fill.

private final boolean
hasPercentageBasedFills

True if there are any fills that are in some way based on the size of the region.

private final boolean
private final List<BackgroundImage>
private final double
opaqueFillBottom

The opaque insets of this Background.

private final double
opaqueFillLeft

The opaque insets of this Background.

private final double
opaqueFillRight

The opaque insets of this Background.

private final double
opaqueFillTop

The opaque insets of this Background.

private final Insets
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
public
Background(final BackgroundFill...
The fills. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of fills. A null array becomes an empty List.
fills
)

Create a new Background by supplying an array of BackgroundFills.

public
Background(final BackgroundImage...
The images. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of images. A null array becomes an empty List.
images
)

Create a new Background by supplying an array of BackgroundImages.

public
Background(final List<BackgroundFill>
The fills. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of fills. A null List becomes an empty List.
fills
,
final List<BackgroundImage>
The images. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of images. A null List becomes an empty List.
images
)

Create a new Background supply two Lists, one for background fills and one for background images.

public
Background(final BackgroundFill[]
The fills. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of fills. A null array becomes an empty List.
fills
,
final BackgroundImage[]
The images. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of images. A null array becomes an empty List.
images
)

Create a new Background by supplying two arrays, one for background fills, and one for background images.

private
Background(List<BackgroundFill>
the fills, not null
fills
,
List<BackgroundImage>
the images, not null
images
,
int ignored)

Creates a new Background with the specified fills and images.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
computeOpaqueInsets(double
The width of the region
width
,
double
The height of the region
height
,
double[]
A four-element array of doubles in order: top, right, bottom, left.
trbl
)

Computes the opaque insets for a region with the specified width and height.

private void
computeOpaqueInsets(double
The width of the region
width
,
double
The height of the region
height
,
boolean
Whether this is being called from the constructor
firstTime
,
double[]
A four-element array of doubles in order: top, right, bottom, left.
trbl
)

Computes the opaque insets.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static Background

Returns:

a new background of the given fill
fill
(Paint
the fill of the background. If null, Color.TRANSPARENT will be used.
fill
)

A convenience factory method for creating a Background with a single Paint.

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public final List<BackgroundFill>

Returns:

the list of BackgroundFills
getFills
()

The list of BackgroundFills which together define the filled portion of this Background.

public final List<BackgroundImage>

Returns:

the list of BackgroundImages
getImages
()

The list of BackgroundImages which together define the image portion of this Background.

public final Insets

Returns:

the outsets
getOutsets
()

The outsets of this Background.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Background
interpolate(Background endValue, double t)

Implements javafx.animation.Interpolatable.interpolate.

Returns an intermediate value between the value of this Interpolatable and the specified endValue using the linear interpolation factor t, ranging from 0 (inclusive) to 1 (inclusive).

public final boolean

Returns:

true if the Background is empty, false otherwise.
isEmpty
()

Gets whether the background is empty.

public boolean

Returns:

True if any CornerRadii of any BackgroundFill on this background would return true, false otherwise.
isFillPercentageBased
()

Gets whether the fill of this Background is based on percentages (that is, relative to the size of the region being styled).

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

BACKGROUND_COLORback to summary
pack-priv static final CssMetaData<Node, Paint[]> BACKGROUND_COLOR
BACKGROUND_IMAGEback to summary
pack-priv static final CssMetaData<Node, Image[]> BACKGROUND_IMAGE
BACKGROUND_INSETSback to summary
pack-priv static final CssMetaData<Node, Insets[]> BACKGROUND_INSETS
BACKGROUND_POSITIONback to summary
pack-priv static final CssMetaData<Node, BackgroundPosition[]> BACKGROUND_POSITION
BACKGROUND_RADIUSback to summary
pack-priv static final CssMetaData<Node, CornerRadii[]> BACKGROUND_RADIUS
BACKGROUND_REPEATback to summary
pack-priv static final CssMetaData<Node, RepeatStruct[]> BACKGROUND_REPEAT
BACKGROUND_SIZEback to summary
pack-priv static final CssMetaData<Node, BackgroundSize[]> BACKGROUND_SIZE
EMPTYback to summary
public static final Background EMPTY

An empty Background, useful to use instead of null.

fillsback to summary
private final List<BackgroundFill> fills
hashback to summary
private final int hash

The cached hash code computation for the Background. One very big reason for making Background immutable was to make it possible to cache and reuse the same Background instance for multiple Regions (for example, every un-hovered Button should have the same Background instance). To enable efficient caching, we cache the hash.

hasOpaqueFillback to summary
private final boolean hasOpaqueFill

Specifies whether the Background has at least one opaque fill.

hasPercentageBasedFillsback to summary
private final boolean hasPercentageBasedFills

True if there are any fills that are in some way based on the size of the region. For example, if a CornerRadii on the fill is percentage based in either or both dimensions.

hasPercentageBasedOpaqueFillsback to summary
private final boolean hasPercentageBasedOpaqueFills
imagesback to summary
private final List<BackgroundImage> images
opaqueFillBottomback to summary
private final double opaqueFillBottom

The opaque insets of this Background.

opaqueFillLeftback to summary
private final double opaqueFillLeft

The opaque insets of this Background.

opaqueFillRightback to summary
private final double opaqueFillRight

The opaque insets of this Background.

opaqueFillTopback to summary
private final double opaqueFillTop

The opaque insets of this Background.

outsetsback to summary
private final Insets outsets
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

Backgroundback to summary
public Background(final BackgroundFill... fills)

Create a new Background by supplying an array of BackgroundFills. This array may be null, or may contain null values. Any null values will be ignored and will not contribute to the fills or outsets.

Parameters
fills:BackgroundFill[]

The fills. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of fills. A null array becomes an empty List.

Backgroundback to summary
public Background(final BackgroundImage... images)

Create a new Background by supplying an array of BackgroundImages. This array may be null, or may contain null values. Any null values will be ignored and will not contribute to the images.

Parameters
images:BackgroundImage[]

The images. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of images. A null array becomes an empty List.

Backgroundback to summary
public Background(final List<BackgroundFill> fills, final List<BackgroundImage> images)

Create a new Background supply two Lists, one for background fills and one for background images. Either list may be null, and may contain nulls. Any null values in these lists will be ignored and will not contribute to the fills, images, or outsets.

Parameters
fills:List<BackgroundFill>

The fills. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of fills. A null List becomes an empty List.

images:List<BackgroundImage>

The images. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of images. A null List becomes an empty List.

Backgroundback to summary
public Background(final BackgroundFill[] fills, final BackgroundImage[] images)

Create a new Background by supplying two arrays, one for background fills, and one for background images. Either array may be null, and may contain null values. Any null values in these arrays will be ignored and will not contribute to the fills, images, or outsets.

Parameters
fills:BackgroundFill[]

The fills. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of fills. A null array becomes an empty List.

images:BackgroundImage[]

The images. This may be null, and may contain nulls. Any contained nulls are filtered out and not included in the final List of images. A null array becomes an empty List.

Backgroundback to summary
private Background(List<BackgroundFill> fills, List<BackgroundImage> images, int ignored)

Creates a new Background with the specified fills and images. This constructor requires that both lists do not contain null values, and that the lists are immutable. The purpose of this constructor is to prevent an unnecessary array creation when the caller already knows that the specified lists satisfy the non-null precondition and preserve the immutability invariant.

Parameters
fills:List<BackgroundFill>

the fills, not null

images:List<BackgroundImage>

the images, not null

Method Detail

computeOpaqueInsetsback to summary
pack-priv void computeOpaqueInsets(double width, double height, double[] trbl)

Computes the opaque insets for a region with the specified width and height. This call must be made whenever the width or height of the region change, because the opaque insets are based on background fills, and the corner radii of a background fill can be percentage based. Thus, we need to potentially recompute the opaque insets whenever the width or height of the region change. On the other hand, if there are no percentage based corner radii, then we can simply return the pre-computed and cached answers.

Parameters
width:double

The width of the region

height:double

The height of the region

trbl:double[]

A four-element array of doubles in order: top, right, bottom, left.

computeOpaqueInsetsback to summary
private void computeOpaqueInsets(double width, double height, boolean firstTime, double[] trbl)

Computes the opaque insets. The first time this is called from the constructor we want to take the long route through and compute everything, whether there are percentage based insets or not (the constructor ensures not to call it in the case that it has percentage based insets!). All other times, this is called by the other computeOpaqueInsets method with "firstTime" set to false, such that if we have percentage based insets, then we will bail early. This method takes into account both fills and images. Because images can be lazy loaded, we cannot pre-compute a bunch of things in the constructor for images the way we can with fills. Instead, each time the method is called, we have to inspect the images. However, we do have fast paths for cases where fills are used and not images.

Parameters
width:double

The width of the region

height:double

The height of the region

firstTime:boolean

Whether this is being called from the constructor

trbl:double[]

A four-element array of doubles in order: top, right, bottom, left.

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
fillback to summary
public static Background fill(Paint fill)

A convenience factory method for creating a Background with a single Paint.

Implementation Specification

This call is equivalent to new Background(new BackgroundFill(fill, null, null));.

Parameters
fill:Paint

the fill of the background. If null, Color.TRANSPARENT will be used.

Returns:Background

a new background of the given fill

Since
18
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

getFillsback to summary
public final List<BackgroundFill> getFills()

The list of BackgroundFills which together define the filled portion of this Background. This List is unmodifiable and immutable. It will never be null. The elements of this list will also never be null.

Returns:List<BackgroundFill>

the list of BackgroundFills

getImagesback to summary
public final List<BackgroundImage> getImages()

The list of BackgroundImages which together define the image portion of this Background. This List is unmodifiable and immutable. It will never be null. The elements of this list will also never be null.

Returns:List<BackgroundImage>

the list of BackgroundImages

getOutsetsback to summary
public final Insets getOutsets()

The outsets of this Background. This represents the largest bounding rectangle within which all drawing for the Background will take place. The outsets will never be negative, and represent the distance from the edge of the Region outward. Any BackgroundImages which would extend beyond the outsets will be clipped. Only the BackgroundFills contribute to the outsets.

Returns:Insets

the outsets

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
interpolateback to summary
public Background interpolate(Background endValue, double t)

Implements javafx.animation.Interpolatable.interpolate.

Doc from javafx.animation.Interpolatable.interpolate.

Returns an intermediate value between the value of this Interpolatable and the specified endValue using the linear interpolation factor t, ranging from 0 (inclusive) to 1 (inclusive).

The returned value might not be a new instance; the implementation might also return one of the two existing instances if the intermediate value would be equal to one of the existing values. However, this is an optimization and applications should not assume any particular identity of the returned value.

Annotations
@Override
Exceptions
NullPointerException:
if endValue is null
Since
24
isEmptyback to summary
public final boolean isEmpty()

Gets whether the background is empty. It is empty if there are no fills or images.

Returns:boolean

true if the Background is empty, false otherwise.

isFillPercentageBasedback to summary
public boolean isFillPercentageBased()

Gets whether the fill of this Background is based on percentages (that is, relative to the size of the region being styled). Specifically, this returns true if any of the CornerRadii on any of the fills on this Background has a radius that is based on percentages.

Returns:boolean

True if any CornerRadii of any BackgroundFill on this background would return true, false otherwise.

Since
JavaFX 8.0