Skip to main content

GradientFill Class

Gradient fill.

Declaration

public class GradientFill extends OutlineFill

Remarks

The following example applies a linear gradient fill to the presentation slide background:

The following code snippet creates a linear gradient with three color stops.

Themed Backgrounds - Gradient Fill, DevExpress Presentation API for Java

import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.*;
import java.util.*;

// Define gradient stops.
List<GradientStop> gradientStops = new ArrayList<GradientStop>() {{
    new GradientStop(Color.getCornsilk(), 10);
    new GradientStop(Color.getAliceBlue(), 30);
    new GradientStop(Color.getRoyalBlue(), 90);
}};

// Create a linear gradient fill.
GradientFill fill = new GradientFill(GradientType.LINEAR, gradientStops);

// Create a blank slide.
Slide slide = new Slide(SlideLayoutType.BLANK, "Slide_Name");

// Apply the gradient background.
slide.setBackground(new CustomSlideBackground(fill));

The following example applies a gradient fill to a shape:

package presentation;

import com.devexpress.docs.presentation.*;
import com.devexpress.docs.office.*;
import com.devexpress.system.drawing.Color;

public class App {
    public static void main(String[] args) throws Exception {
        //...
        Shape shape1 = new Shape(ShapeType.getRectangle());
        SolidFill solidFill = new SolidFill(Color.getRoyalBlue());
        LineStyle outlineStyle = new LineStyle();
        outlineStyle.setFill(solidFill);
        outlineStyle.setWidth(8);
        shape1.setOutline(outlineStyle);
        shape1.setX(1100);
        shape1.setY(1100);
        shape1.setWidth(300);
        shape1.setHeight(300);
        slide.getShapes().add(shape1);

        GradientFill fill = new GradientFill(GradientType.LINEAR);
        fill.getGradientStops().add(new GradientStop(Color.getCornsilk(), 10));
        fill.getGradientStops().add(new GradientStop(Color.getAliceBlue(), 50));
        fill.getGradientStops().add(new GradientStop(Color.getRoyalBlue(), 90));
        fill.setScaled(true);
        shape1.setFill(fill);
    }
}

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
JavaObject

Constructors

GradientFill(GradientType gradientType, List<GradientStop> gradientStops) Constructor

Initializes a new instance of the GradientFill class with specified settings.

Declaration

public GradientFill(GradientType gradientType, List<GradientStop> gradientStops)

Parameters

Name Type Description
gradientType GradientType

Specifies the type of gradient.

gradientStops java.util.List<GradientStop>

Specifies the collection of gradient stops.

GradientFill(GradientType gradientType, OfficeColor color1, OfficeColor color2) Constructor

Initializes a new instance of the GradientFill class with specified settings.

Declaration

public GradientFill(GradientType gradientType, OfficeColor color1, OfficeColor color2)

Parameters

Name Type Description
gradientType GradientType

Specifies the type of gradient.

color1 OfficeColor

Specifies the first gradient color.

color2 OfficeColor

Specifies the second gradient color.

Methods

deepClone() Method

Returns a deep copy of this GradientFill instance.

Declaration

public GradientFill deepClone()

Returns

Type Description
GradientFill

A deep copy of this GradientFill.

getAngle() Method

Returns the direction of the linear gradient in degrees.

Declaration

public float getAngle()

Returns

Type Description
float

The direction of the linear gradient in degrees.

getFillRect() Method

Returns the rectangle area where the gradient is applied.

Declaration

public RectangleOffset getFillRect()

Returns

Type Description
RectangleOffset

The rectangle area where the gradient is applied.

getFlipType() Method

Returns how the gradient is flipped when tiled.

Declaration

public FlipType getFlipType()

Returns

Type Description
FlipType

Flipping mode.

getGradientStops() Method

Returns the collection of color points in the gradient.

Declaration

public IGradientStopCollection getGradientStops()

Returns

Type Description
com.devexpress.docs.office.IGradientStopCollection

A collection of gradient stops.

getGradientType() Method

Returns the type of gradient applied to a shape.

Declaration

public GradientType getGradientType()

Returns

Type Description
GradientType

Gradient type.

getRotateWithShape() Method

Indicates whether the gradient fill rotates along with the shape.

Declaration

public boolean getRotateWithShape()

Returns

Type Description
boolean

true if the gradient fill rotates along with the shape; otherwise, false.

getScaled() Method

Determines whether the gradient scales with the object to which it is applied.

Declaration

public boolean getScaled()

Returns

Type Description
boolean

true if the gradient scales with the object; otherwise, false.

getTileRect() Method

Returns the rectangular region to which a gradient is applied. This region is tiled to fill the object.

Declaration

public RectangleOffset getTileRect()

Returns

Type Description
RectangleOffset

An object that specifies offsets (as a percentage) from the edges of a shape’s bounding box to the tile rectangle. A positive percentage specifies an inset, and a negative percentage defines an outset.

getType() Method

Returns the fill type.

Declaration

public FillType getType()

Returns

Type Description
FillType

Fill type.

setAngle(float value) Method

Sets the direction of the linear gradient in degrees.

Declaration

public void setAngle(float value)

Parameters

Name Type Description
value float

The direction of the linear gradient in degrees.

setFillRect(RectangleOffset value) Method

Sets the rectangle area where the gradient is applied.

Declaration

public void setFillRect(RectangleOffset value)

Parameters

Name Type Description
value RectangleOffset

The rectangle area where the gradient is applied.

setFlipType(FlipType value) Method

Sets how the gradient is flipped when tiled.

Declaration

public void setFlipType(FlipType value)

Parameters

Name Type Description
value FlipType

Flipping mode.

setGradientType(GradientType value) Method

Sets the type of gradient applied to a shape.

Declaration

public void setGradientType(GradientType value)

Parameters

Name Type Description
value GradientType

Gradient type.

setRotateWithShape(boolean value) Method

Indicates whether the gradient fill rotates along with the shape.

Declaration

public void setRotateWithShape(boolean value)

Parameters

Name Type Description
value boolean

true if the gradient fill rotates along with the shape; otherwise, false.

setScaled(boolean value) Method

Determines whether the gradient scales with the object to which it is applied.

Declaration

public void setScaled(boolean value)

Parameters

Name Type Description
value boolean

true if the gradient scales with the object; otherwise, false.

setTileRect(RectangleOffset value) Method

Sets the rectangular region to which a gradient is applied. This region is tiled to fill the object.

Declaration

public void setTileRect(RectangleOffset value)

Parameters

Name Type Description
value RectangleOffset

An object that specifies offsets (as a percentage) from the edges of a shape’s bounding box to the tile rectangle. A positive percentage specifies an inset, and a negative percentage defines an outset.