IntelliJ Java IDE
The moose likes Game Development and the fly likes Instantiated components from within a thread aren’t repainting into a JFrame in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Game Development
Reply locked New topic
Author

Instantiated components from within a thread aren’t repainting into a JFrame in Java

Rigoberto Vides
Greenhorn

Joined: Feb 19, 2010
Posts: 4
Hi guys, I'm making this tetris variation, a piece should be spawned every 2 secs. I try to construct this piece (Block) from within a thread like this:


I'm using swingUtilities.invokeLater to send this thread to the swing event dispatcher, everything looks to work normal (i.e. the blocks instantiate each timeToSpawn) milisecs... but there is one BIG problem: they don't show on the Jframe! On the other hand whenever I just instantiate 1 or n blocks from within the same JFrame class like this for example:



They work perfectly fine and paint on the JFrame. What a mess.. I've been like crazy figuring out what's happening! My Block class extends Component and implements Runnable, it's run method looks like this:


It's a thread to update it's position each 450 milisecs... could this be the problem? although as I mentioned before, I just test this code and it worked, the problem is when I instantiate an object of this class within another thread.

As final and extra info. whenever I check the method toString on the Instantiated cubes from threads, they give me this [,0,0,0x0], but when I instantiate them within the same JFrame class they give me this result [,0,0,328x552] and they appear on the frame. this 328x552 value it's the same as the component's Dimension returned by getPreferredSize()... I tried to force them to that dimension by instantiate them like this:



But it didn't work, anyone knows what this [,0,0,328x552] value could mean?

Thanks in advance Everyone!


Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
 
subject: Instantiated components from within a thread aren’t repainting into a JFrame in Java
 
Threads others viewed
Instantiated components from within a thread aren’t repainting into a JFrame in Java
Applet working in appletviewer but no browser
GUI display(rendering) problem
java upgrade makes modal dialog lock up application
Can anyone help me
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com