开发者

How to center Label vertical and horizontal in draw2d Figure?

开发者 https://www.devze.com 2022-12-26 21:11 出处:网络
I have the following situation: Label label = new Label(); label.setText(\"bla\"); RoundedRectangle fig = new RoundedRectangle();

I have the following situation:

Label label = new Label();
label.setText("bla");
RoundedRectangle fig = new RoundedRectangle();
fig.add(label);
FlowLayout layout = new FlowLayout();
layout.setStretchMinorAxis(true);
fig.setLayoutManager(layout开发者_开发问答);
fig.setOpaque(true);

That works only to center the label vertical or horizontal by using layout.setHorizontal(true/false); , but not together. Any idea how to make it work ?


Try something like this:

Label label = new Label();
label.setText("bla");
label.setTextAlignment(PositionConstants.CENTER);

RoundedRectangle fig = new RoundedRectangle();    
fig.setLayoutManager(new BorderLayout());
fig.add(label, BorderLayout.CENTER);


i solved my problem to centralize label names using Simon's answers. Thx

setLayoutManager(new BorderLayout());
labelName.setTextAlignment(PositionConstants.CENTER);
add(labelName, BorderLayout.CENTER);
setBackgroundColor(ColorConstants.lightBlue);
0

精彩评论

暂无评论...
验证码 换一张
取 消