首页 文章

标签垂直对齐不起作用

提问于
浏览
1

我有一个带有Icon的Label,我试图在底部设置垂直对齐,但它不起作用 . 是一个问题吗?

Form hi = new Form("Label");
hi.add(new Button("Upper Border"));
Label bottomLabel = new Label("Label Text Bottom");
bottomLabel.setIcon(theme.getImage("Orange Line.png"));
bottomLabel.setVerticalAlignment(Component.BOTTOM);
hi.add(bottomLabel);
hi.add(new Button("Bottom Border"));
hi.show();

enter image description here

EDITED

我不打算实现上图所示的确切布局 . 这只是我需要的一个例子 . 我希望能够添加带有Icon的标签并在底部设置文本 . 但我不想使用容器来做,因为我需要在底部添加几行包含Icon和文本的行 . 以下是我想要学习的例子:

enter image description here

1 回答

  • 1

    您可以使用borderlayout在表单底部设置标签,如下面的代码所示 . 我更改了表单的布局并将标签设置为底部

    Form hi = new Form("Label");
        **hi.setLayout(new BorderLayout());**
        hi.add(BorderLayout.NORTH,new Button("Upper Border"));
        Label bottomLabel = new Label("Label Text Bottom");
        bottomLabel.setIcon(theme.getImage("Orange Line.png"));
        bottomLabel.setVerticalAlignment(Component.BOTTOM);
        **hi.add(BorderLayout.SOUTH,bottomLabel);**
       //hi.add(new Button("Bottom Border"));
        hi.show();
    

相关问题