7

I'm trying to arrange and scale some elements inside a table and I need to know the Table's height in order to achieve all that. The problem is that whenever I try to get its height it always returns 0 even though the table is obviously on the screen and has a definite size. Why is that?

table_height = table.getHeight();
gogonapel
  • 788
  • 6
  • 17
  • 2
    It depends when you are asking for the height. If you call this after you add elements to it, but before it has been updated, it will still be zero. Normally, the table's size is based on what is inside it, so I'm not sure if this will work anyway. But you can call `table.invalidateHierarchy()` to force it to calculate its current size early. – Tenfour04 Dec 13 '14 at 18:18
  • I've tested invalidateHierarchy in the constructor, after I added all the elements to the table; it still yielded 0.0 . Is there any way I can get the height in the constructor? – gogonapel Dec 14 '14 at 09:08
  • I should also say that the table has a Stack inside it that contains other tables , and imagebuttons. – gogonapel Dec 14 '14 at 11:06

1 Answers1

10

I suggest you to use the method pack() on the table before calling getHeight(). This will set your table its height and width.

table.pack();
table_height = table.getHeight();
Gregzenegair
  • 361
  • 4
  • 7