• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with repaint()

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic