0

I just had a problem with artifacts at a JPanel which contains transparent parts. My JPanel overrides the paintComponent() method:

protected void paintComponent(Graphics g) {
    g2d = (Graphics2D) g;
    drawMyAplhaImage(g2d);
}

Repaint Artifacts

As you can see, the Image drawn on the JPanel is a bit smaller than the JPanel itself.

nidomiro
  • 820
  • 2
  • 10
  • 24

1 Answers1

0

The solution is to redraw the Parent component.

To save ressources I just repaint the area of the JPanel.

The new paintComponent() method:

protected void paintComponent(Graphics g) {
    g2d = (Graphics2D) g;
    getParent().repaint(getX(), getY(), getWidth(), getHeight());
    drawMyAplhaImage(g2d);
}
nidomiro
  • 820
  • 2
  • 10
  • 24