【问题标题】:How to center Label vertical and horizontal in draw2d Figure?如何在draw2d图中将标签垂直和水平居中?
【发布时间】:2010-04-16 10:00:19
【问题描述】:
我有以下情况:
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);
这仅适用于使用 layout.setHorizontal(true/false); 使标签垂直或水平居中。 ,但不在一起。知道如何使它工作吗?
【问题讨论】:
标签:
java
layout
figure
draw2d
【解决方案1】:
试试这样的:
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】:
我使用 Simon 的答案解决了集中标签名称的问题。谢谢
setLayoutManager(new BorderLayout());
labelName.setTextAlignment(PositionConstants.CENTER);
add(labelName, BorderLayout.CENTER);
setBackgroundColor(ColorConstants.lightBlue);