Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Frequent repainting  RSS feed

 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a double for loop inside which I have to repaint JtabbedPane for every cycle. It works well if I put whole method into event-queue thread. But in that situation I can't interrupt this repainting, because pressing the "Stop repainting" button causes its event to came after all repainting had been done.

But, on the other side, if I put this method (containing double foor loops) into separate thread I get visual missmatch between for loops and repainting of JTabbedPane, because they run in separate threads, i.e. event-queue is always late.

Is there any way I can get information about when JTabbedPane repainting has been finished?
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Velika,

Instead of putting the whole double for loop on the event thread you could just send one repaint event at a time and wait for it to complete. If you separate your updates and block until they complete:

You can look for your "Stop Repainting" event between calls.
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it won't work. Calculations in the double for loop are so quick so that JVM's redraw of JLayeredPane can't follow it.

Somehow dirty solution came into my mind. I could put all calculations into event-queue followed by the JLayeredPane repaint. But, there is another problem. Putting all calculations into run() method, will cause problems with variables scope, because run() method will reside in the inner anonymous class.
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have worked it out.

I have put whole method, including double for loop, into new Thread and called update of JLayeredPane through invokeAndWait method (not recommended way, but it works well for me).

Thank you @Darrin Cartwright, for your advice. I knew there was a method invokeAndWait, but as you know, its usage is not recommended, so I was trying to use invokeLater but failed every time with it. Your advice has encouraged me. Thanks again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!