Skip to main content

JPanel / Canvas refreh problems

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
aranbarri
Offline
Joined: 2011-01-02

First of all, hi to all, this is my first post in this thread and I just registered because of a problem i'm having with Swing.
Well, I have a Panel inside a Frame which consists of a Canvas that I need to update in real time. Shortly, when you clicks on an option a different image must appear.

I have no problems on displaying the image, but when the user clicks another option, the old image doesn't dissappear, so the new one shows above the old one. I'm trying repaint, removeAll, etc but nothing seems to work.

This is the code of the paintComponent() method:

public void paintComponent(Graphics g){
super.paintComponents(g);
this.removeAll();
this.repaint();
(...) painting method (...)

...
}

Any suggestions? Thanks in advance