aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Multithreaded Rendering 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 "Multithreaded Rendering" Watch "Multithreaded Rendering" New topic
Author

Multithreaded Rendering

Andy Selador
Ranch Hand

Joined: May 02, 2008
Posts: 34
I am trying to have a task that takes some time (drawing a correctly-sized graph on a BufferedImage using a large series of drawLine() calls). Once this task completes, a JPanel should then use drawImage() to draw the BufferedImage on the screen. I have this all set up using SwingWorker and a PropertyChangeListener ("done" is the important one). The problem is a new SwingWorker subclass (DrawCurveTask) is instantiated and execute()d with every component resize, and the JPanel redraws itself at the completion of every one of these DrawCurveTasks. Does anyone have any ideas on how to make it stop updating itself when the window isn't being resized anymore (i.e. you drag the window all over the place for awhile, stop, and watch the line continuously rerender until all the tasks have executed).

I had tried removing the PropertyChangeListener of all but the newest task, but this meant that it wouldn't redraw with the most recently finished task, and instead would wait for the newest execute()d task to complete. Its kind of a weird problem, so any advice is good.

Also, is there a way to make it work so that a new thread isn't required, but without holding up the paintComponent() method?

Completely unrelated: What are the advantages of using a thread pool? I ask because I just thought of the number of threads that may accumulate (I know SwingWorker sets the limit at 10 running threads, but a more general scenario would be nice).

Thanks,

Andy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multithreaded Rendering
 
Similar Threads
Framework for GUI with computationally intensive threads
Caching & Scaling BufferedImage/Image?
How do I render and draw buffered Images in Parallel? - JFreeChart Question
How to update JTextField from child thread?
Java swing background execution