布局管理器,用于在Java中设置此特定布局 [英] Layout managers to set this specific layout in java

查看:92
本文介绍了布局管理器,用于在Java中设置此特定布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要对此作业进行编程的布局,这是我第一次在GUI中使用布局管理器,因此在使布局匹配时遇到了问题.我需要你的帮助

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

我有两个标签为帐户创建"和帐户转帐"的标签(都可以),我需要的是在一行中包含JLabel(帐户ID)和第一个文本字段,然后在第二行中包含下一个JLabel(金额)和文本字段.线下第一条.在此之下需要以JButton为中心(创建帐户).最后,JTextArea(无帐户)需要位于与标签,文本字段和按钮分开的空白区域的右列中.

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.

这是我开始使用的代码:

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.

以上是嵌套或复合布局的示例.带有标题的边框显示了所使用的布局以及用于构造它们的参数(如果有).

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).

要在文本字段中获得TALL效果,请设置HUGE字体,但使用较少的列作为构造函数.

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

另一种嵌套布局.

这篇关于布局管理器,用于在Java中设置此特定布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆