Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

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

 
Rigoberto Vides
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic