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

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.

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).

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)

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

posted Dec 28, 2011 00:04:31

0

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?

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

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com

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