java怎样设置布局管理器,布局管理器,用于在Java中设置此特定布局

I have this layout that I need to program for an assignment and this is the first time I have used layout managers in the GUI so I'm having problems getting the layout to match. I need your help

I Have two tabs labeled Account creation and Account transfer (those are ok) what I need is to have the JLabel (Account ID) and the first text field in one line then the next JLabel (Amount) and text field in the line under the first. Under that needs to be the JButton Centered (Create an Account). Lastly the JTextArea (No account) needs to be in a column to the right in the empty space separate from the labels, text fields, and button.

Cbs1B.png

Here is the code I have started with:

public CreatePanel(Vector accountList, TransferPanel transferPanel)

{

this.accountList = accountList;

this.transferPanel = transferPanel;

JLabel l1 = new JLabel("Account ID");

JTextField t1 = new JTextField();

JLabel l2 = new JLabel("Amount");

JTextField t2 = new JTextField();

JButton b1 = new JButton("Create an Account");

JTextArea a1 = new JTextArea("No Account");

JPanel panel1 = new JPanel();

panel1.setLayout(new GridLayout(2,3));

panel1.add(l1);

panel1.add(t1);

panel1.add(l2);

panel1.add(t2);

panel1.add(b1, BorderLayout.SOUTH);

b1.setVerticalAlignment(JLabel.CENTER);

JPanel panel2 = new JPanel();

panel2.add(a1);

a1.setSize(200, 300);

add(panel1);

add(panel2);

}

解决方案

This is how I would approach it. Instead of adding the outer panel to a frame though, it would be added to a tab of the tabbed pane.

29qDK.png

The above is an example of a nested or compound layout. The titled borders show the layouts used and the arguments (if any) used to construct them.

The size of the button is suggested by the content (the text). The sizes of the text fields and text area is suggested in the constructor (which itself has been included as the text value).

To get the TALL effect in the text fields, set an HUGE font but use less columns for the constructor.

See also

Jaqap.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值