• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Frequent repainting

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic