public class GradientStyle
extends java.lang.Object
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);
| Modifier and Type | Field and Description |
|---|---|
static int |
DIAGONAL_DOWN
Diagonal gradient moving from a top corner down to the opposite corner.
|
static int |
DIAGONAL_UP
Diagonal gradient moving from a bottom corner up to the opposite corner.
|
static int |
FROM_CENTER
Gradient running from the center out to the corners.
|
static int |
FROM_CORNER
Gradient running from a corner to the other three corners.
|
static int |
HORIZONTAL
Gradient running horizontally across an object.
|
static int |
length |
static int |
NONE
No gradient.
|
static int |
VERTICAL
Gradient running vertically down an object.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String gradientStyleName) |
static java.lang.String |
getName(int gradientStyle) |
static int[] |
getValues() |
static java.lang.String |
toString(int gradientStyle) |
public static int NONE
public static int HORIZONTAL
public static int VERTICAL
public static int DIAGONAL_UP
public static int DIAGONAL_DOWN
public static int FROM_CORNER
public static int FROM_CENTER
public static int length