【问题标题】: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.setHorizo​​ntal(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);
      

      【讨论】:

        猜你喜欢
        • 2013-07-12
        • 1970-01-01
        • 2010-11-20
        • 2013-05-18
        • 2018-01-06
        • 2022-01-09
        • 2021-06-30
        • 2017-03-06
        相关资源
        最近更新 更多