我有以下情况:
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)将标签垂直或水平居中; ,但不在一起。知道如何让它发挥作用吗?
最佳答案
尝试这样的事情:
Label label = new Label();
label.setText("bla");
label.setTextAlignment(PositionConstants.CENTER);
RoundedRectangle fig = new RoundedRectangle();
fig.setLayoutManager(new BorderLayout());
fig.add(label, BorderLayout.CENTER);
关于java - 如何在draw2d图中垂直和水平居中标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2652028/