aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes removing a painted component via paintComponent leaves a residue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "removing a painted component via paintComponent leaves a residue" Watch "removing a painted component via paintComponent leaves a residue" New topic
Author

removing a painted component via paintComponent leaves a residue

Ned Perez
Greenhorn

Joined: Nov 18, 2011
Posts: 10
hi new mates, its just my first time, here. hello. i hope i cant state my ideas properly.

im about to create a , you can say a complex GUI, which will have tons of animated and customized Components such as Panels(panes) Buttons etc.. , and as of now, im on the start, trying to create a sliding looking pop window made from JPanel, by using Thread handling, i manage to make the panel 'appear' just like what i want, it slides from a certain point up to the desired dimension, via paintComponent and some Thread tweaking(well im not sure if what im doing is efficient or proper ), i was able to do the task, the problem is on 'removing'. for a certain command like 'click' , the 'window looking JPanel' will be removed vice versa of how it appeared, when i try to remove it, the code that i wrote REMOVES the 'window looking JPanel' but at some point it LEAVES A RESIDUE(a vertical line), while i was trying to look for some bugs before i jump into another task i stuck up with this one,, ill post the code below so it can be tested , this is as short as it goes, i hope it dont bother too much

the main class


the CustomDialogPanel - the panel that is used to portrait a pop window looking component


the only questions i got right now, despite of how i search with the help of google friend is that,
1.) why does it leaves a residue of the panel?
2.) even though i try to remove it from its parentComponent , why does it still leaves a residue?

// EDIT
when i try to minimize the window(hide it), then show it again, the residue disappears
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Add super.paintComponent(g); as the first line of the overridden paintComponent method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ned Perez
Greenhorn

Joined: Nov 18, 2011
Posts: 10
the problem still exist.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2183
    
    7
1) Dont call your class Window. There is an AWT component Window which is confusing.

2) Don't use updateUI(). Instead use reapaint() to tell a component to repaint itself.

3) Don't use a Thread. Instead use a Swing Timer to schedule the animation. This will make sure painting code is execute on the Event Dispatch Thread.

I tried running your code but I don't understand how to use it. I clicked on the panel and a painting occurs from the top/left to bottom/right. I couldn't figure out how to remove the painting so I don't see a residue.
Ned Perez
Greenhorn

Joined: Nov 18, 2011
Posts: 10
i forgot to tell what is the goal task of the program, a click event will trigger the window(JPanel), it will actually trigger if some components will be clicked(i.e button or something clickable) but as of now i just directly added a mouselistener to the frame to test the opening of that JPanel window. so regardless of what part of the frame ill will click the window(JPanel) will slide(open), a dummy button on the top-left most part, will test the closing of the window-panel,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: removing a painted component via paintComponent leaves a residue