java - 如何在draw2d图中垂直和水平居中标签?

标签 java layout figure draw2d

我有以下情况:

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.setHorizo​​ntal(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/

相关文章:

forms - ExtJS - 在 FormPanel 列布局中排列表单元素

jquery - android 上的 float : how to fit the screen size

python - 来自 matplotlib 的 pickle 数字

具有不可序列化部分的 Java 序列化

java - 使用迭代器模式java使用一个循环打印出两个数据结构

c++ - 如何为布局激活 adjustsize()

html - 在图像旁边放置 figcaption

java - 从打开的 JComboBox 中打开 JPopupMenu

java - hibernate 将 java Long 映射到 MySQL BIGINT 错误

python - 图形用户界面 (GUI) 的 python 包的正确布局