Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

jpanel getWidth returns 0

807591Apr 4 2008 — edited Apr 5 2008
I have a jframe using flowlayout which displays a variable number of jpanels. I don't want to display more than can fit on 1 row of the jframe. I'm trying somthing like this:

for ...
get object from vector
create a new gamePanel with object attributes (extends jpanel)

totalWidth += game.getWidth();
if (totalWidth <= windowWidth)
this.add(gp);
else break;

Unfortunatly getWidth returns 0 everytime, so if I have say 10 objects in the Vector I end up with 2 rows of gamePanels on the jframe. Is there any way to stop flowlayout from starting a new row. Or is there a way to find out the width of the gamePanels?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 3 2008
Added on Apr 4 2008
2 comments
461 views