GradientStyle
Contents
[
Hide
]Inheritance: java.lang.Object
public class GradientStyle
Specifies the style for a gradient fill.
Examples:
Shows how to fill a shape with a gradients.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
// Apply One-color gradient fill to the shape with ForeColor of gradient fill.
shape.getFill().oneColorGradient(Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2, 0.1);
Assert.assertEquals(Color.RED.getRGB(), shape.getFill().getForeColor().getRGB());
Assert.assertEquals(GradientStyle.HORIZONTAL, shape.getFill().getGradientStyle());
Assert.assertEquals(GradientVariant.VARIANT_2, shape.getFill().getGradientVariant());
Assert.assertEquals(270, shape.getFill().getGradientAngle());
shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
// Apply Two-color gradient fill to the shape.
shape.getFill().twoColorGradient(GradientStyle.FROM_CORNER, GradientVariant.VARIANT_4);
// Change BackColor of gradient fill.
shape.getFill().setBackColor(Color.YELLOW);
// Note that changes "GradientAngle" for "GradientStyle.FromCorner/GradientStyle.FromCenter"
// gradient fill don't get any effect, it will work only for linear gradient.
shape.getFill().setGradientAngle(15.0);
Assert.assertEquals(Color.YELLOW.getRGB(), shape.getFill().getBackColor().getRGB());
Assert.assertEquals(GradientStyle.FROM_CORNER, shape.getFill().getGradientStyle());
Assert.assertEquals(GradientVariant.VARIANT_4, shape.getFill().getGradientVariant());
Assert.assertEquals(0, shape.getFill().getGradientAngle());
// Use the compliance option to define the shape using DML if you want to get "GradientStyle",
// "GradientVariant" and "GradientAngle" properties after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); }
doc.save(getArtifactsDir() + "Shape.GradientFill.docx", saveOptions);
Fields
Field | Description |
---|---|
DIAGONAL_DOWN | Diagonal gradient moving from a top corner down to the opposite corner. |
DIAGONAL_UP | Diagonal gradient moving from a bottom corner up to the opposite corner. |
FROM_CENTER | Gradient running from the center out to the corners. |
FROM_CORNER | Gradient running from a corner to the other three corners. |
HORIZONTAL | Gradient running horizontally across an object. |
NONE | No gradient. |
VERTICAL | Gradient running vertically down an object. |
length |
Methods
Method | Description |
---|---|
fromName(String gradientStyleName) | |
getName(int gradientStyle) | |
getValues() | |
toString(int gradientStyle) |
DIAGONAL_DOWN
public static int DIAGONAL_DOWN
Diagonal gradient moving from a top corner down to the opposite corner.
DIAGONAL_UP
public static int DIAGONAL_UP
Diagonal gradient moving from a bottom corner up to the opposite corner.
FROM_CENTER
public static int FROM_CENTER
Gradient running from the center out to the corners.
FROM_CORNER
public static int FROM_CORNER
Gradient running from a corner to the other three corners.
HORIZONTAL
public static int HORIZONTAL
Gradient running horizontally across an object.
NONE
public static int NONE
No gradient.
VERTICAL
public static int VERTICAL
Gradient running vertically down an object.
length
public static int length
fromName(String gradientStyleName)
public static int fromName(String gradientStyleName)
Parameters:
Parameter | Type | Description |
---|---|---|
gradientStyleName | java.lang.String |
Returns: int
getName(int gradientStyle)
public static String getName(int gradientStyle)
Parameters:
Parameter | Type | Description |
---|---|---|
gradientStyle | int |
Returns: java.lang.String
getValues()
public static int[] getValues()
Returns: int[]
toString(int gradientStyle)
public static String toString(int gradientStyle)
Parameters:
Parameter | Type | Description |
---|---|---|
gradientStyle | int |
Returns: java.lang.String