如何在draw2d图中居中Label标签?

时间:2022-09-05 23:04:35

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 ?

这只能通过使用layout.setHorizo​​ntal(true / false)使标签垂直或水平居中; ,但不是在一起。知道如何让它工作吗?

2 个解决方案

#1


1  

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);

#2


0  

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

我解决了我的问题,使用Simon的答案集中标签名称。谢谢

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

#1


1  

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);

#2


0  

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

我解决了我的问题,使用Simon的答案集中标签名称。谢谢

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