aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JPanel paintcomponent in runnable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel paintcomponent in runnable" Watch "JPanel paintcomponent in runnable" New topic
Author

JPanel paintcomponent in runnable

Muteking Tonello
Greenhorn

Joined: Jul 18, 2013
Posts: 8
I've been wrapping my head for days around that. I want to make a circle move in a JPanel. I've set up a paintcomponent method with a graphic object and it's been repainted inside the EDT.
Oracle docs say that you can't draw with Swing outside EDT.
But then, how do I do it?


Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

First, you don't need a Thread / Runnable. Use a javax.swing,Timer instead.

Oracle docs say that you can't draw with Swing outside EDT.
But then, how do I do it?

All Swing constructors and methods should be invoked on the EDT, with the exception of the very few that are documented as being thread-safe. And for that, consult the Java 7 documentation; several methods that were earlier documented as thread-safe never were, and the documentation has been corrected in 7.

Once you use a Timer, you won't have a problem about firing updates on the EDT, but you may like to learn more about the techniques for doing so. You'll find all you need in the tutorial on Concurrency in Swing.


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Oh, and since this is about Swing I'll move this thread to where we usually discuss such matters.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel paintcomponent in runnable