aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes weird and unwanted duplicate component is being painted, moving a component(Simple animation) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "weird and unwanted duplicate component is being painted, moving a component(Simple animation)" Watch "weird and unwanted duplicate component is being painted, moving a component(Simple animation)" New topic
Author

weird and unwanted duplicate component is being painted, moving a component(Simple animation)

Ned Perez
Greenhorn

Joined: Nov 18, 2011
Posts: 10
sorry for the long title of my thread, but its quite difficult to formulate an exact statement for my problem
first of all merry Christmas to all, happy holidays

heres the code 2 Classes
the SlidingPanel, a custom component, which is used on different classes



the class that uses the custom panel


i reproduce this code from the application that im writing at the moment, the sliding component is used to display an image when a mouse cursor intersects a rectangle. Now, when i run the program, the logic works, when i move the mouse cursor rectangle to the target rectangle, it moves according to where i want it to be, at first on the original program, the class that uses this custom component has an image background painted via overridden paintComponent() method, so i didnt notice the problem until i removed the image background, then i saw (i don't know if i should call it a flickering) a copy of the sliding custom component, a little bit transparent painted from location (0, 0) with same dimension, with just a little flicker, that every time the custom component is moving , something the same is being painted location(0, 0). i really don't know what is going on, the only problem that i got from web is a flickering problem, i dont even know what word or statement to ask Google, or if there is someone with the same problem that i can look into. I need some help, thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

SlidingPanel should call super.paintComponent(g) as the first line of its paintComponent method. Also, SampleApp should override paintComponent and call super.paintComponent(g) instead of overriding paint and calling super.paint(g).


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
i modified the code, instead of overriding paint, i changed it into paintComponent() with a call to super.paintComponent() on both classes, but it still paints the duplicate on same location, and by the way i used paint() instead of paintComponent() on SlidingPanel, because it paints a border of a JPanel, and it's implementation on the original program is transparent(a transparent component)
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

i used paint() instead of paintComponent() on SlidingPanel, because it paints a border of a JPanel,

i know this doesn't address your problem but you can draw a border quite easily


SCJP
Visit my download page
Ned Perez
Greenhorn

Joined: Nov 18, 2011
Posts: 10
i know this doesn't address your problem but you can draw a border quite easily

yes, by changing it to paintCompoent() it will differ the task that i want for customizing component, but hey thank you for giving me an idea to alter the logic of what i want, a Border. im not yet trying it,ill try to find a way with the border thing idea you gave me, ill just hope someone will see this thread that has the same problem or who can actually tell me what is wrong , i've read everything i can find on google regarding with painting in java, also the oracle article that discusses briefly about painting events. But sadly i still cant figure out whats going on.. thanks a lot
Ned Perez
Greenhorn

Joined: Nov 18, 2011
Posts: 10
hello again, setting the border still doesn't solve the duplicate component that is appearing on that certain area.. is this a bug? or fairly technical issue that i violated when it comes to animating/painting a custom component?
Prabakar Kalivaradan
Greenhorn

Joined: Dec 12, 2011
Posts: 20

Hi,

I noticed the trail marks disappear, after the mouse movement. Also the JComponent.setBounds() method API says "This method changes layout-related information, and therefore,
invalidates the component hierarchy." which doesn't happen as soon as the sliding panel moves to the new location. Though I don't understand why there is a delay in invalidating the component hierarchy, it made easy to get a workaround. Calling repaint() manually as shown below, fixes the problem. Hope this helps.



-prabak
 
wood burning stoves
 
subject: weird and unwanted duplicate component is being painted, moving a component(Simple animation)