This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to draw in a jPanel using multi-threading? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "How to draw in a jPanel using multi-threading?" Watch "How to draw in a jPanel using multi-threading?" New topic
Author

How to draw in a jPanel using multi-threading?

vinderela mistery
Greenhorn

Joined: Jan 02, 2013
Posts: 7

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

Joined: Oct 27, 2005
Posts: 19216

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
vinderela mistery
Greenhorn

Joined: Jan 02, 2013
Posts: 7
Thank you!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

You're welcome.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to draw in a jPanel using multi-threading?
 
Similar Threads
HashMap - in-memory caching - multi-threaded environment ?
session management in tomcat
Multi-Threading in J2ME
multithreading in servlets
Concurrent Programming & Multi-threading book recommendation