This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Painting with threads using paint/repaint() and run()  RSS feed

 
Terence Gronowski
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to paint a big amount of data in a thread with some delay in betwenn. I want to be able to stop and start the painting. As using graphics you have to draw with the paint() method. The examples I saw used a repaint() mehtod in the run method of the tread. It should be possible too, to enter Values while painting is on the way.

This is a very unfavorable way to program that problem using the repaint() method. Each time repaint() is called in run() paint() should draw just a part of the data, which is very hard to program.



In the above code I paint all the data in the paint() Method.

Question: How can I combine paint/repaint() with the run() Merhod?
 
Rob Spoor
Sheriff
Posts: 21089
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should really read Concurrency in Swing. In short, you should never sleep on the Event Dispatcher Thread. In this case you can probably use either a javax.swing.Timer or a SwingWorker. You should also override paintComponent, not paint, and then call super.paintComponent(g) as the first statement.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!