0
votes

I have a Label object with a text in it...

Label label = new Label(text);

..and I get the height by...

label.pack();
GlyphLayout layout = label.getGlyphLayout();
float height = layout.height;

When I add them to a table I just said

Table t = new Table();
t.add(label).width(200).height(height); 

Currently I work on a chat window and each entry of the window is a Label containing a colored name and text, like... enter image description here

Note: The debug lines are drawn. Please ignore the blue line, it's from another table in the scene

Now my question: The 1-liner has a glyphlayout height of 38 and the 3-liner 139. Does someone know why there's such a big gap between the 2 entries resp. why the 3-liner height doesn't seem to be correct? No extra spacing / padding.

I would appreciate any ideas to solve this.

1
Please do not add SOLVED to your title if you solved the question by yourself. If you feel this question has value for other Stack Overflow users, post the solution to your question as an answer and accept that answer. If you feel this question has no value to other SO users, delete the question (there is a delete link underneath your question). - TT.
accepting is possible in two days - Lukas__

1 Answers

0
votes

SOLVED: My post was incomplete, sorry. I set the width of the label before calling...

label.setWidth(x); // where x was < chatbox width
label.pack();

So the GlyphLayout assumed a width which was smaller than the actual chatbox width. The result is of course a bigger height...

Thanks a lot to the libgdx IRC, especially Tomski :)