aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to: call repaint() 4 times from other class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to: call repaint() 4 times from other class." Watch "How to: call repaint() 4 times from other class." New topic
Author

How to: call repaint() 4 times from other class.

Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
Hi all,

I have a question about calling repaint() method from other class. The problem is that I can't call repaint() 4 times from other class. The result is always something like this:

trying to repaint() 1 times...
trying to repaint() 2 times...
trying to repaint() 3 times...
trying to repaint() 4 times...
trying to repaint() 5 times...
Actually doing repaint() 5 times...


Below I have included the code I am talking about.

I am sorry for the trouble but thank you beforehand.

Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
The problem is that I can't call repaint() 4 times from other class.


I meant 5 times, sorry.

My preferred result would be:

trying to repaint() 1 times...
Actually doing repaint() 1 times...
trying to repaint() 2 times...
Actually doing repaint() 2 times...
trying to repaint() 3 times...
Actually doing repaint() 3 times...
trying to repaint() 4 times...
Actually doing repaint() 4 times...
trying to repaint() 5 times...
Actually doing repaint() 5 times...

Any help would be greatly appreciated.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
You seem to be under the impression that each call to repaint() results in a call to paint()/paintComponent().

This is not the case, which is a good thing. In general we like that mulitple calls to repaint() may be coalesced into a single paint()/paintCoponent() call. It keeps our GUIs responsive.

So, why are you trying to do this? (If you are trying to achieve an animation effect, then you probably want to call repaint() from a timer.)

[edit: Looking more closely at your code, I see I may have misjudged your problem. For example, with new ViewControl(rdius).repaint() you are requesting that a newly-instantiated ViewControl object (which is not added to any container) repaint itself. It seems what you really want to do is call myExistingViewControl.repaint(), where myExistingViewControl is a reference to a single ViewControl object that you have already added to some visible container.]
[ October 08, 2007: Message edited by: Brian Cole ]

bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to: call repaint() 4 times from other class.
 
Similar Threads
How to: synchronize sockets?
Need help on animation using GUI Builder.
How to: convert "guarded block" into "lock objects"?
can't add to JPanel after removeAll() is triggered by another swing component
How to: clear the JPanel before repainting?