• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with repaint()

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I am calling repaint() on an object of class that extends JPanel.
Directly after calling repaint(), I need to call a method, see below:

However, the board isn't being repainted, till after someMethod returns.

I tried using...


But that didn't work either. Can anyone help me solve this, perhaps this needs to go in the threads section, but I'm not sure.

Thanks for any help
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
repaint() tells the Swing event thread to paint the component -- the call to paintComponent() does not happen on the thread that calls repaint(). If you want to do something after the painting is completed, then either your paint method needs to notify the thread that called repaint() somehow, or you need to schedule that activity to run on the event thread using SwingUtilities.invokeLater() or invokeAndWait(), or perhaps most simply, you can do that thing in the paintComponent() method itself.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried calling the method at the end of the paintComponent method, but it was still running the method first before it got to draw to the screen.

I will take a look at the other options you mentioned. But I do have a thread allergy, which doesn't help
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey.. I got it working (First Time!!!)
I basically put got it to output 1 to 1000 AFTER drawing the screen:



I don't fully understand it, but I get the jist of it, thanks
[ April 18, 2006: Message edited by: colin shuker ]
reply
    Bookmark Topic Watch Topic
  • New Topic