gpt4 book ai didi

java - 左下角内容带边框布局

转载 作者:行者123 更新时间:2023-12-01 04:48:16 26 4
gpt4 key购买 nike

我想向我的面板添加状态栏。

实际上,它看起来像这样:

enter image description here

但我希望文字显示在左下角。

这是我的代码:

private JPanel pnl1, pnl2;
//pnl1 contains everything exept the status bar, pnl2 only status bar
private JLabel lab3;
//lab3 is the status bar
(…)

public static void main(String[] args) {
new Panel1();
}

public Panel1() {

pnl1 = new JPanel();
pnl2 = new JPanel();

lab3 = new JLabel("Started."); //Statusbar
(…)
pnl1.setLayout(new FormLayout(
"40*($lcgap, 10dlu)",
"30*($lgap, 10dlu)"
));
CellConstraints cc = new CellConstraints();

pnl1.add(…)
pnl2.add(lab3);

this.add(pnl1);
this.add(pnl2, BorderLayout.PAGE_END);
this.(…)

感谢您的帮助!

最佳答案

您正在将标签添加到 pnl2 中,但似乎没有更改布局。 JPanel 的默认布局是 FlowLayout ,它使用居中对齐。

如果您希望标签向左对齐,可以使用FlowLayout,确保对齐方式设置为LEADING:

    pnl2.setLayout(new FlowLayout(FlowLayout.LEADING));
pnl2.add(lab3);

或者您可以使用不同的布局,例如BorderLayout:

    pnl2.setLayout(new BorderLayout());
pnl2.add(lab3);

关于java - 左下角内容带边框布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15459755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com