1
votes

I have a gwt TextBox whose height is determined by a variable:

aTextBox = new TextBox();
parentLayoutPanel.add(aTextBox);
parentLayoutPanel.setWidgetTopHeight(aTextBox, 0.0, Unit.PX, text_box_height, Unit.PX);

This variable text_box_height is unknown until the page loads. Now I want to make sure the font inside the box matches the size of the box. Currently, I'm attempting to the following:

aTextBox.getElement().getStyle().setProperty("fontSize", Integer.toString(text_box_height) + "px");

Unfortunately, this results in white space above the text which cuts off the bottom of the text:

textBoxFont

How can I remove this white space/padding? Or is there a different way to size and position the text in the box? Thank you much!

EDIT: Additional information: Due to the comments, I've added the following image. The line is the cursor marker. enter image description here

2
Use a different letter - like F - and you will see a very different white space. - Andrei Volgin
@AndreiVolgin I still get the same white space with an 'F'. - golmschenk
Have you tried vertical-align: middle; ?? - Suresh Atta
@TheSureshAtta, attempting that now. It didn't seem to work, but when I look at the resulting source code I don't seem to see the style add the input element. Maybe I'm missing something... - golmschenk
@TheSureshAtta, nevermind. The style is correctly added, but I am still getting the same thing. - golmschenk

2 Answers

0
votes

You can set padding on TextBox just like you can set it on any element. You can use .getElement().getStyle(), or you can apply a CSS style.

0
votes

After some more research I've found that the space taken up by the line of text is 1.5x that of the font-size. I don't see a way to change that whitespace. I ended up actually just setting the box being 1.5x as much as the font-size.