Customize Slide Background — Presentation API for Java
- 4 minutes to read
The DevExpress Presentation API allows you to customize slide backgrounds with theme-based fills, solid colors, gradients, patterns, and images.
You can apply a background directly to an individual slide or define a background on a slide layout or slide master to ensure a consistent appearance across multiple slides.
Background Inheritance
PowerPoint presentations use the following background inheritance hierarchy:
- Presentation Theme
- Slide Master
- Slide Layout
- Slide
Slides inherit their background settings from their layout or slide master. When you assign a background directly to a slide, the slide uses its own background settings instead of the inherited background.
Apply a Theme Background
A presentation theme defines a set of colors, fonts, and visual effects that can be reused throughout a presentation.
Use the ThemedSlideBackground class to apply a background fill defined in the presentation theme. This class exposes the following methods:
| Method | Description |
|---|---|
| setFillIndex(int value) | Specifies the theme fill style. Valid values are in the range [1..999]. |
| setColor(OfficeColor value) | Specifies the background fill color. |
The following code snippet applies the second fill style defined in the current theme and changes its color.

import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.Color;
import com.devexpress.docs.OfficeColor;
// Create a themed background that uses the second fill style defined in the theme.
ThemedSlideBackground themedBackground = new ThemedSlideBackground(2);
// Specify the fill color.
themedBackground.setColor(new OfficeColor(Color.getRoyalBlue()));
// Apply the background to the slide.
slide.setBackground(themedBackground);
Note
A valid presentation theme requires at least three fill definitions. These definitions may include solid fills, gradient fills, or other supported fill types.
Refer to the following help topic for additional information: Customize Presentation Themes.
Apply a Custom Background
Use the CustomSlideBackground class when you need full control over slide appearance. This class exposes the following methods:
| Method | Description |
|---|---|
| setFill(Fill value) | Specifies the background fill type. |
| setShadeToTitle(boolean value) | Specifies whether to apply title shading effects. |
Solid Fill
Use a SolidFill to fill the slide background with a single color.
The following code snippet creates a slide with a light cyan background:

import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.Color;
// Create a blank slide.
Slide slide = new Slide(new SlideLayout(SlideLayoutType.BLANK, "Slide"));
// Create a solid fill.
SolidFill fill = new SolidFill(Color.getLightCyan());
// Apply the solid fill as a custom slide background.
slide.setBackground(new CustomSlideBackground(fill));
Gradient Fill
Use a GradientFill to create smooth color transitions.
GradientFill exposes the following methods:
| Method | Description |
|---|---|
| getGradientStops() | Gets the collection of gradient stops. |
| setGradientType(GradientType value) | Specifies the gradient type (LINEAR, RADIAL, RECTANGULAR, or SHAPE). |
| setAngle(float value) | Specifies the rotation angle of a linear gradient. |
| setFillRect(RectangleOffset value) | Specifies the gradient fill area. |
| setTileRect(RectangleOffset value) | Specifies the gradient tile area. |
| setFlipType(FlipType value) | Specifies how the gradient is flipped. |
| setScaled(boolean value) | Specifies whether the gradient is scaled. |
The following code snippet creates a linear gradient with three color stops.

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));
Pattern Fill
Use a PatternFill to fill the background with a repeating pattern.
PatternFill exposes the following methods:
| Method | Description |
|---|---|
| setPatternType(FillPatternType value) | Specifies a pattern. |
| setBackgroundColor(OfficeColor value) | Specifies the pattern background color. |
| setForegroundColor(OfficeColor value) | Specifies the pattern foreground color. |
You can also specify these values in the PatternFill constructor.
The following code snippet creates a diagonal cross pattern:

import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.*;
// Create a pattern fill.
PatternFill fill =
new PatternFill(
FillPatternType.DIAGONAL_CROSS,
Color.getWhite(),
Color.getRoyalBlue());
// Create a blank slide.
Slide slide = new Slide(SlideLayoutType.BLANK, "Slide_Blank");
// Apply the pattern background.
slide.setBackground(new CustomSlideBackground(fill));
Picture Fill
Use a PictureFill to use an image as the slide background.
PictureFill exposes the following methods:
| Method | Description |
|---|---|
| Constructor | Specify the background image. |
| setAlignType(TileAlignType value) | Specifies image alignment. |
| setFillRect(RectangleOffset value) | Specifies the area of the slide to fill. |
| setSourceRect(RectangleOffset value) | Specifies the source image area to use. |
| setFlipType(FlipType value) | Specifies image flipping behavior. |
| setOffsetX(float value), setOffsetY(float value) | Specify image offsets. |
| setScaleX(float value), setScaleY(float value) | Specify image scaling factors. |
| setStretch(boolean value) | Specifies whether the image is stretched to fill the slide. |

import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.*;
import com.devexpress.docs.office.*;
import java.io.FileInputStream;
// Create a blank slide.
Slide slide = new Slide(SlideLayoutType.BLANK, "Slide_Blank");
// Load an image and use it as a slide background.
try (FileInputStream stream = new FileInputStream("background.png")) {
PictureFill fill = new PictureFill(DXImage.fromStream(stream));
// Stretch the image to fit the slide.
fill.setStretch(true);
slide.setBackground(new CustomSlideBackground(fill));
}
Apply Backgrounds to Multiple Slides
To maintain a consistent appearance throughout a presentation, consider applying backgrounds to:
- A slide master when all presentation slides should share the same background.
- A slide layout when only slides based on a specific layout should share the same background.
- Individual slides when only specific slides require a custom appearance.