Interface Painter

All Known Implementing Classes:
BackgroundPainter, GlassTutorial, PainterChain, Timeline

public interface Painter

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);
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Draws inside the given rectangle clipping area.
  • Method Details

    • paint

      void paint(Graphics g, Rectangle rect)

      Draws inside the given rectangle clipping area.

      Parameters
      • g: the Graphics object

      • rect: the given rectangle cliping area