java boxlayout_Java BoxLayout使用中的问题

想使用BoxLayout,但是出现故障,故障如下,麻请达人指点,谢谢!Exceptioninthread"main"java.awt.AWTError:BoxLayoutcan'tbeshared-----------------------------------------------...

想使用BoxLayout,但是出现故障,故障如下,麻请达人指点,谢谢!

Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared

-----------------------------------------------------

import javax.swing.*;

/**

*

* @author Administrator

*/

public class Login extends JFrame {

private JLabel jLabel1, jLabel2, jLabel3;

private JButton jConnect, jCancel;

private JTextField jUID;

private JPasswordField jPwd;

Login() {

super("登录界面");

jLabel1 = new JLabel("家庭收入管理系统");

jLabel2 = new JLabel("用户名");

jLabel3 = new JLabel("密码");

jConnect = new JButton("连接");

jCancel = new JButton("取消");

jUID = new JTextField("");

jPwd = new JPasswordField("");

Box title = Box.createHorizontalBox();

Box userName = Box.createHorizontalBox();

Box password = Box.createHorizontalBox();

Box submitButton = Box.createHorizontalBox();

title.add(jLabel1);

userName.add(jLabel2);

userName.add(jUID);

password.add(jLabel3);

password.add(jPwd);

submitButton.add(jConnect);

submitButton.add(jCancel);

this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));

this.add(title);

this.add(userName);

this.add(password);

this.add(submitButton);

title.setVisible(true);

userName.setVisible(true);

password.setVisible(true);

submitButton.setVisible(true);

this.setLocation(50, 50);

this.setSize(500, 500);

this.setVisible(true);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public static void main(String[] args) {

// TODO code application logic here

new Login();

}

}

吴琼的答案是使用FlowLayout,是可以运行的。

但我觉得比较困惑的是为什么BoxLayout不行??

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值