public interface Painter

Known subtypesTimeline, BackgroundPainter, PainterChain, GlassTutorial

Painter can be used to draw on components backgrounds. The use of this interface allows reuse of a background Painter for various components.

A simple example of a background painter is shown here to draw a circle background:

Component cmp = new Label("Round Background");
Painter p = new Painter() {
    public void paint(Graphics g, Rectangle rect) {
        boolean antiAliased = g.isAntiAliased();
        g.setAntiAliased(true);
        try {
            int r = Math.min(rect.getWidth(), rect.getHeight()) / 2;
            int x = rect.getX() + rect.getWidth() / 2 - r;
            int y = rect.getY() + rect.getHeight() / 2 - r;
            g.setColor(0x3f51b5);
            g.fillArc(x, y, r * 2, r * 2, 0, 360);
        } finally {
            g.setAntiAliased(antiAliased);
        }
    }
};
cmp.getStyle().setBgPainter(p);

Methods

public abstract void paint(Graphics g, Rectangle rect)Draws inside the given rectangle clipping area.

Method details

paint

public abstract void paint(Graphics g, Rectangle rect)
Draws inside the given rectangle clipping area.

Parameters

g Graphics
the Graphics object
rect Rectangle
the given rectangle cliping area