How to draw graphics in Swing rather than using an AWT Canvas on a Swing Component?

Scott Stanchfield

You simply subclass JComponent and override its paintComponent() method. Do not override paint(), as the default version of paint does much more.

For example

public class MyComponent extends JComponent {
  public void paintComponent(Graphics g) {
    // perform painting here...