Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to draw in a jPanel using multi-threading?  RSS feed

 
vinderela mistery
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have to draw Mandelbrot set. I use a BufferedImage and generate each pixel in the paintComponent method. How can I use multi-threading? because I can not use g.drawImage in run method.

Regards,
Vinderela
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, all the drawing needs to occur in one single thread - the Event Dispatcher Thread (EDT). Read Concurrency in Swing for more information.

Of course you can run multiple threads that all post the necessary events to the EDT using either EventQueue.invokeLater (*) or a SwingWorker and its publish method.


* SwingUtilities.invokeLater simply calls EventQueue.invokeLater.
 
vinderela mistery
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!