APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.scene.layout

public final Class BackgroundSize

extends Object
implements Interpolatable<BackgroundSize>
Class Inheritance
All Implemented Interfaces
javafx.animation.Interpolatable
Imports
com.sun.javafx.util.InterpolationUtils, javafx.animation.Interpolatable, javafx.beans.NamedArg, java.util.Objects

Defines the size of the area that a BackgroundImage should fill relative to the Region it is styling. There are several properties whose values take precedence over the others. In particular there are 4 key properties, width, height, contain, and cover. Both width and height are independent of each other, however both interact with contain and cover.

From the CSS Specification, cover is defined to:

Scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.
contain is defined to:
Scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.
And width and height both specify (in absolute values or percentages) the size to use. These two properties only apply if both cover and contain are false. If both cover and contain are true, then cover will be used.

The width and height may also be set to AUTO, indicating that the area should be sized so as to use the image's intrinsic size, or if it cannot be determined, 100%.

Since
JavaFX 8.0

Field Summary

Modifier and TypeField and Description
public static final double
AUTO

From the CSS Specification:

An "auto" value for one dimension is resolved by using the image's intrinsic ratio and the size of the other dimension, or failing that, using the image's intrinsic size, or failing that, treating it as 100%.

If both values are "auto" then the intrinsic width and/or height of the image should be used, if any, the missing dimension (if any) behaving as "auto" as described above. If the image has neither an intrinsic width nor an intrinsic height, its size is determined as for "contain".

private final boolean
private final boolean
public static final BackgroundSize
DEFAULT

The default BackgroundSize used by BackgroundImages when an explicit size is not defined.

private final int
hash

A cached hash code value

private final double
private final boolean
private final double
private final boolean

Constructor Summary

AccessConstructor and Description
public
BackgroundSize(double
The width. Cannot be less than 0, except for the value of AUTO.
width
,
double
The height. Cannot be less than 0, except for the value of AUTO.
height
,
boolean
Whether the width is to be interpreted as a percentage
widthAsPercentage
,
boolean
Whether the height is to be interpreted as a percentage
heightAsPercentage
,
boolean
Whether the image should be sized to fit within the Region maximally
contain
,
boolean
Whether the image should be sized to "cover" the Region
cover
)

Create a new BackgroundSize.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object o)

Overrides java.lang.Object.equals.

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

public final double

Returns:

the height of the area within the Region where the associated BackgroundImage should render
getHeight
()

The height of the area within the Region where the associated BackgroundImage should render.

public final double

Returns:

the width of the area within the Region where the associated BackgroundImage should render
getWidth
()

The width of the area within the Region where the associated BackgroundImage should render.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public BackgroundSize
interpolate(BackgroundSize 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.

private static double
interpolate(double start, double end, boolean startIsPercentage, boolean endIsPercentage, double t)

public final boolean

Returns:

true if the image can fit inside the background positioning area
isContain
()

If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.

public final boolean

Returns:

true if image can completely cover the background positioning area
isCover
()

If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.

public final boolean

Returns:

true if height should be interpreted as a percentage
isHeightAsPercentage
()

Specifies whether the value contained in height should be interpreted as a percentage or as a normal value.

private boolean
isSame(double width, double height, boolean widthAsPercentage, boolean heightAsPercentage)

public final boolean

Returns:

true if width should be interpreted as a percentage
isWidthAsPercentage
()

Specifies whether the value contained in width should be interpreted as a percentage or as a normal value.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTOback to summary
public static final double AUTO

From the CSS Specification:

An "auto" value for one dimension is resolved by using the image's intrinsic ratio and the size of the other dimension, or failing that, using the image's intrinsic size, or failing that, treating it as 100%.

If both values are "auto" then the intrinsic width and/or height of the image should be used, if any, the missing dimension (if any) behaving as "auto" as described above. If the image has neither an intrinsic width nor an intrinsic height, its size is determined as for "contain".

When set to AUTO, the values for widthAsPercentage and heightAsPercentage are ignored.
containback to summary
private final boolean contain
coverback to summary
private final boolean cover
DEFAULTback to summary
public static final BackgroundSize DEFAULT

The default BackgroundSize used by BackgroundImages when an explicit size is not defined. By default, the BackgroundSize is AUTO, AUTO for the width and height, and is neither cover nor contain.

hashback to summary
private final int hash

A cached hash code value

heightback to summary
private final double height
heightAsPercentageback to summary
private final boolean heightAsPercentage
widthback to summary
private final double width
widthAsPercentageback to summary
private final boolean widthAsPercentage

Constructor Detail

BackgroundSizeback to summary
public BackgroundSize(double width, double height, boolean widthAsPercentage, boolean heightAsPercentage, boolean contain, boolean cover)

Create a new BackgroundSize.

Parameters
width:double

The width. Cannot be less than 0, except for the value of AUTO.

height:double

The height. Cannot be less than 0, except for the value of AUTO.

widthAsPercentage:boolean

Whether the width is to be interpreted as a percentage

heightAsPercentage:boolean

Whether the height is to be interpreted as a percentage

contain:boolean

Whether the image should be sized to fit within the Region maximally

cover:boolean

Whether the image should be sized to "cover" the Region

Method Detail

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
getHeightback to summary
public final double getHeight()

The height of the area within the Region where the associated BackgroundImage should render. If set to AUTO, then heightAsPercentage is ignored. This value has no meaning if either contain or cover are specified. This value cannot be negative, except when set to the value of AUTO.

Returns:double

the height of the area within the Region where the associated BackgroundImage should render

getWidthback to summary
public final double getWidth()

The width of the area within the Region where the associated BackgroundImage should render. If set to AUTO, then widthAsPercentage is ignored. This value has no meaning if either contain or cover are specified. This value cannot be negative, except when set to the value of AUTO.

Returns:double

the width of the area within the Region where the associated BackgroundImage should render

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 BackgroundSize interpolate(BackgroundSize 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. The interpolation factor can be any finite value.

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
interpolateback to summary
private static double interpolate(double start, double end, boolean startIsPercentage, boolean endIsPercentage, double t)
isContainback to summary
public final boolean isContain()

If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.

Returns:boolean

true if the image can fit inside the background positioning area

isCoverback to summary
public final boolean isCover()

If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.

Returns:boolean

true if image can completely cover the background positioning area

isHeightAsPercentageback to summary
public final boolean isHeightAsPercentage()

Specifies whether the value contained in height should be interpreted as a percentage or as a normal value.

Returns:boolean

true if height should be interpreted as a percentage

isSameback to summary
private boolean isSame(double width, double height, boolean widthAsPercentage, boolean heightAsPercentage)
isWidthAsPercentageback to summary
public final boolean isWidthAsPercentage()

Specifies whether the value contained in width should be interpreted as a percentage or as a normal value.

Returns:boolean

true if width should be interpreted as a percentage