Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

removing a painted component via paintComponent leaves a residue

 
Ned Perez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add super.paintComponent(g); as the first line of the overridden paintComponent method.
 
Ned Perez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem still exist.
 
Rob Camick
Ranch Hand
Posts: 2584
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic