javascript - GWT: Set text to be in the middle of the label (vertically) - Stack Overflow

I am adding an image and a label to a HorizontalPanel.The image is vertically aligned to the center, b

I am adding an image and a label to a HorizontalPanel. The image is vertically aligned to the center, but the text in the label is always aligned to the top.

I am looking for a way to make the text appear in the middle of the label (and thus in the middle on the panel).

I am adding an image and a label to a HorizontalPanel. The image is vertically aligned to the center, but the text in the label is always aligned to the top.

I am looking for a way to make the text appear in the middle of the label (and thus in the middle on the panel).

Share Improve this question asked Dec 17, 2012 at 18:28 Erik SapirErik Sapir 24.8k29 gold badges86 silver badges144 bronze badges 1
  • If you know the size of the text, you can set the top of the text to be 50% of the parent, then use a negative margin to offset it upwards half of the height of the text. – NickD Commented Dec 17, 2012 at 21:49
Add a ment  | 

2 Answers 2

Reset to default 5
myPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

Use alignment on horizontal panel like below code does.

panel.setCellHorizontalAlignment( image, HasHorizontalAlignment.ALIGN_CENTER );

panel.setCellHorizontalAlignment( label, HasHorizontalAlignment.ALIGN_CENTER );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745036221a4607534.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信