How to Define a Background

To create a custom background, a new class should be created, extending the Background class. Background subclasses have to implement two methods, as explained in the following sections.

Informing whether the background is transparent

The isTransparent() method is called by the MWT framework in order to know whether or not the background is transparent. A background is considered as transparent if it does not draw every pixel with maximal opacity when it is applied.

For example, the following snippet informs that the background is completely opaque regardless of its size:

@Override
public boolean isTransparent(int width, int height) {
        return false;
}

Applying the background on a graphics context

The apply(GraphicsContext g, int width, int height) method is called by the MWT framework in order to render the background and to set or remove the background color of subsequent drawings.

For example, the following snippet applies a white background:

@Override
public void apply(GraphicsContext g, int width, int height) {
        g.setColor(Colors.WHITE);
        Painter.fillRectangle(g, 0, 0, width, height);
        g.setBackgroundColor(Colors.WHITE);
}