Top Description Fields Constructors Methods
javafx.scene.paint

public final Class ImagePattern

extends Paint
Class Inheritance
Imports
javafx.beans.NamedArg, javafx.scene.image.Image, com.sun.javafx.beans.event.AbstractNotifyListener, com.sun.javafx.tk.Toolkit, com.sun.javafx.util.InterpolationUtils, java.util.Objects

The ImagePattern class fills a shape with an image pattern. The user may specify the anchor rectangle, which defines the position, width, and height of the image relative to the upper left corner of the shape. If the shape extends out of the anchor rectangle, the image is tiled.

If the proportional variable is set to true (the default) then the anchor rectangle should be specified relative to the unit square (0.0->1.0) and will be stretched across the shape. If the proportional variable is set to false, then the anchor rectangle should be specified in the local coordinate system of the shape and the image will be stretched to fit the anchor rectangle. The anchor rectangle will not be stretched across the shape.

The example below demonstrates the use of the proportional variable. The shapes on the top row use proportional coordinates (the default) to specify the anchor rectangle. The shapes on the bottom row use absolute coordinates. The flower image is stretched to fill the entire triangle shape, while the dot pattern image is tiled within the circle shape.


import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;

public class HelloImagePattern extends Application {

    private static final String flowerURL = "file:flower.png";
    private static final String dotsURL = "file:dots.png";

    @Override public void start(Stage stage) {
        stage.setTitle("Image Pattern");
        Group root = new Group();
        Scene scene = new Scene(root, 600, 450);

        Image dots = new Image(dotsURL);
        Image flower = new Image(flowerURL);

        Polygon p = new Polygon();

        p.setLayoutX(10);
        p.setLayoutY(10);
        p.getPoints().add(50.0);
        p.getPoints().add(0.0);
        p.getPoints().add(100.0);
        p.getPoints().add(100.0);
        p.getPoints().add(0.0);
        p.getPoints().add(100.0);

        p.setFill(new ImagePattern(flower, 0, 0, 1, 1, true));

        root.getChildren().add(p);

        Polygon p2 = new Polygon();

        p2.setLayoutX(10);
        p2.setLayoutY(120);
        p2.getPoints().add(50.0);
        p2.getPoints().add(0.0);
        p2.getPoints().add(100.0);
        p2.getPoints().add(100.0);
        p2.getPoints().add(0.0);
        p2.getPoints().add(100.0);

        p2.setFill(new ImagePattern(flower, 0, 0, 100, 100, false));

        root.getChildren().add(p2);

        Circle circ = new Circle(50);
        circ.setTranslateX(120);
        circ.setTranslateY(10);
        circ.setCenterX(50);
        circ.setCenterY(50);
        circ.setFill(new ImagePattern(dots, 0.2, 0.2, 0.4, 0.4, true));

        root.getChildren().add(circ);

        Circle circ2 = new Circle(50);
        circ2.setTranslateX(120);
        circ2.setTranslateY(10);
        circ2.setCenterX(50);
        circ2.setCenterY(50);
        circ2.setFill(new ImagePattern(dots, 20, 20, 40, 40, false));

        root.getChildren().add(circ2);
        stage.setScene(scene);
        stage.show();
    }

The code above produces the following:

A visual rendering of the
 HelloImagePattern example

Since
JavaFX 2.2

Field Summary

Modifier and TypeField and Description
private int
private double
private Image
private Object
private boolean
private double
private double
x

private double
y

Constructor Summary

AccessConstructor and Description
public
ImagePattern(Image
the image to be used as the paint.
image
)

Creates a new instance of ImagePattern from the specified image.

public
ImagePattern(Image
the image to be used as the paint.
image
,
double
the x origin of the anchor rectangle.
x
,
double
the y origin of the anchor rectangle.
y
,
double
the width of the anchor rectangle.
width
,
double
the height of the anchor rectangle.
height
,
boolean
whether the coordinates are proportional to the shape which ImagePattern fills
proportional
)

Creates a new instance of ImagePattern.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv Object
pack-priv boolean
pack-priv void
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

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

public final double

Returns:

The height of the anchor rectangle.
getHeight
()

Gets the height of the anchor rectangle.

public final Image

Returns:

Image to be used as a paint.
getImage
()

Gets the image to be used as a paint.

public final double

Returns:

The width of the anchor rectangle.
getWidth
()

Gets the width of the anchor rectangle.

public final double

Returns:

The x origin of the anchor rectangle.
getX
()

Gets the x origin of the anchor rectangle.

public final double

Returns:

The y origin of the anchor rectangle.
getY
()

Gets the y origin of the anchor rectangle.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public ImagePattern

Returns:

the intermediate value
interpolate
(ImagePattern
the target value
endValue
,
double
the interpolation factor
t
)

Implements javafx.animation.Interpolatable.interpolate.

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

public Paint
interpolate(Paint 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
isOpaque()

Implements abstract javafx.scene.paint.Paint.isOpaque.

Gets whether this Paint is completely opaque.

public final boolean

Returns:

boolean that is true if this paint is proportional.
isProportional
()

Gets a boolean that indicates whether start and end locations are proportional or absolute.

Inherited from javafx.scene.paint.Paint:
valueOf

Field Detail

hashback to summary
private int hash
heightback to summary
private double height
imageback to summary
private Image image
platformPaintback to summary
private Object platformPaint
proportionalback to summary
private boolean proportional
widthback to summary
private double width
xback to summary
private double x
yback to summary
private double y

Constructor Detail

ImagePatternback to summary
public ImagePattern(Image image)

Creates a new instance of ImagePattern from the specified image. Default values are used for all other parameters.

Parameters
image:Image

the image to be used as the paint.

Exceptions
NullPointerException:
if the image is null.
IllegalArgumentException:
if image is not done loading, that is if progress is < 1.
ImagePatternback to summary
public ImagePattern(Image image, double x, double y, double width, double height, boolean proportional)

Creates a new instance of ImagePattern.

Parameters
image:Image

the image to be used as the paint.

x:double

the x origin of the anchor rectangle.

y:double

the y origin of the anchor rectangle.

width:double

the width of the anchor rectangle.

height:double

the height of the anchor rectangle.

proportional:boolean

whether the coordinates are proportional to the shape which ImagePattern fills

Exceptions
NullPointerException:
if the image is null.
IllegalArgumentException:
if image is not done loading, that is if progress is < 1.

Method Detail

acc_addListenerback to summary
pack-priv void acc_addListener(AbstractNotifyListener platformChangeListener)

Overrides javafx.scene.paint.Paint.acc_addListener.

Annotations
@Override
acc_getPlatformPaintback to summary
pack-priv Object acc_getPlatformPaint()

Implements abstract javafx.scene.paint.Paint.acc_getPlatformPaint.

Annotations
@Override
acc_isMutableback to summary
pack-priv boolean acc_isMutable()

Overrides javafx.scene.paint.Paint.acc_isMutable.

Annotations
@Override
acc_removeListenerback to summary
pack-priv void acc_removeListener(AbstractNotifyListener platformChangeListener)

Overrides javafx.scene.paint.Paint.acc_removeListener.

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

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()

Gets the height of the anchor rectangle.

Returns:double

The height of the anchor rectangle.

Default Value
1.0
getImageback to summary
public final Image getImage()

Gets the image to be used as a paint.

Returns:Image

Image to be used as a paint.

getWidthback to summary
public final double getWidth()

Gets the width of the anchor rectangle.

Returns:double

The width of the anchor rectangle.

Default Value
1.0
getXback to summary
public final double getX()

Gets the x origin of the anchor rectangle.

Returns:double

The x origin of the anchor rectangle.

Default Value
0.0
getYback to summary
public final double getY()

Gets the y origin of the anchor rectangle.

Returns:double

The y origin of the anchor rectangle.

Default Value
0.0
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 ImagePattern interpolate(ImagePattern endValue, double t)

Implements javafx.animation.Interpolatable.interpolate.

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

Parameters
endValue:ImagePattern

the target value

t:double

the interpolation factor

Returns:ImagePattern

the intermediate value

Exceptions
NullPointerException:
if endValue is null
Since
24
interpolateback to summary
public Paint interpolate(Paint 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
isOpaqueback to summary
public final boolean isOpaque()

Implements abstract javafx.scene.paint.Paint.isOpaque.

Doc from javafx.scene.paint.Paint.isOpaque.

Gets whether this Paint is completely opaque. An opaque paint is one that has no alpha component in any of its colors. It may be possible for a Paint to be opaque and yet return false, if it cannot be easily determined whether the paint is actually opaque. For example, the ImagePattern may not be able to cheaply determine its opacity.

Annotations
@Override
isProportionalback to summary
public final boolean isProportional()

Gets a boolean that indicates whether start and end locations are proportional or absolute. If this flag is true, the two end points are defined in a coordinate space where coordinates in the range [0..1] are scaled to map onto the bounds of the shape that the pattern fills. If this flag is false, then the coordinates are specified in the local coordinate system of the node.

Returns:boolean

boolean that is true if this paint is proportional.

Default Value
true