jpanel getWidth returns 0
807591Apr 4 2008 — edited Apr 5 2008I 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?