整个程序布局为this. GridLayout(5,1)
把整个分为5行 再在把这对应的5部分 定义
5个面版 每个面版在自定义比如最上面的一个
定义为Panel P1=new Panel();
p1.setLayout(new GridLayout(1,2));下面的就面版就是P2,P3,P4,P5
把整个分为5行 再在把这对应的5部分 定义
5个面版 每个面版在自定义比如最上面的一个
定义为Panel P1=new Panel();
p1.setLayout(new GridLayout(1,2));下面的就面版就是P2,P3,P4,P5
解决方案 »
- Swing 如何更新界面?
- 用Java如何导入导出txt、Excel、doc、xml文件
- 一个简单程序的错误,谢谢您来纠正
- 请教一个关于子类方法屏蔽父类方法的问题
- 组件用不了,不知道是怎么回事
- 【求助】为什么内部类传参要求对象是final的?不然就会编译错误?是出于什么考虑呢?
- JLabel边框如何显示出来?
- $$$ 有 谁 知 道 Highlighter 怎 么 用 吗 ? $$$
- boolean 类型的数据应如何存入数据类型为bit的数据表字段中,
- 如何用JAVA编写测试本机上是否有FTP服务?
- java.util.Properties类的使用
- Java中运算符能否重载,String的=号和+又是如何实现的呢?
setlayout(null)
import java.awt.*;public class Layout extends JFrame
{
Container cp;
JLabel jlname,jladdress,jlnum,jlmailid;
JTextField jtfname,jtfnum,jtfmailid;
JScrollPane jspaddress;
JTextArea jtaaddress;
GridBagLayout gbl;
GridBagConstraints gbc;
public Layout()
{
setTitle("Layout Show");
setBounds(20,20,350,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jlname=new JLabel("Customer Name:");
jladdress=new JLabel("Current Address:");
jlnum=new JLabel("Phone Number:");
jlmailid=new JLabel("E-MAIL ID:");
jtfname=new JTextField(15);
jtaaddress=new JTextArea(3,15);
jspaddress=new JScrollPane(jtaaddress);
jspaddress.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jtfnum=new JTextField(15);
jtfmailid=new JTextField(15);
cp=getContentPane();
gbc=new GridBagConstraints();
gbc.fill=GridBagConstraints.BOTH;
gbc.insets=new Insets(4,4,4,4);
gbl=new GridBagLayout();
cp.setLayout(gbl);
gbc.gridx=0;
gbc.gridy=0;
gbc.gridheight=1;
gbc.gridwidth=1;
cp.add(jlname,gbc);
gbc.gridx=1;
cp.add(jtfname,gbc);
gbc.gridx=0;
gbc.gridy=1;
cp.add(jladdress,gbc);
gbc.gridx=1;
gbc.gridheight=3;
cp.add(jspaddress,gbc);
gbc.gridx=0;
gbc.gridy=4;
gbc.gridheight=1;
cp.add(jlnum,gbc);
gbc.gridx=1;
cp.add(jtfnum,gbc);
gbc.gridx=0;
gbc.gridy=5;
cp.add(jlmailid,gbc);
gbc.gridx=1;
cp.add(jtfmailid,gbc);
}
public static void main(String[] args)
{
Layout l=new Layout();
l.setVisible(true);
}
}
最下面的可以用一个panel其布局为gridlayout两行一列
用GridBagLayot是可以的,但教师给的提示是用null layout,但就是不会用。
把整个分为5行 再在把这对应的5部分 定义
5个面版 每个面版在自定义比如最上面的一个
定义为Panel P1=new Panel();
p1.setLayout(new GridLayout(1,2));下面的就面版就是P2,P3,P4,P5
GridBagLayout 就可以了。 楼主该揭帖了,呵呵。*******************************************************************
import javax.swing.*;
import java.awt.*;
public class MyLayout extends JFrame {
private JPanel jPanel1 = new JPanel();
private JLabel label1 = new JLabel();
private JLabel label2 = new JLabel();
private JLabel label3 = new JLabel();
private JLabel label4 = new JLabel();
private JTextField textField1 = new JTextField();
private JEditorPane editorPane1 = new JEditorPane();
private JScrollPane scrollPane = new JScrollPane();
private JTextField textField2 = new JTextField();
private JTextField textField3 = new JTextField();
private GridBagLayout gridBagLayout1 = new GridBagLayout();
public static void main(String[] args) {
} public MyLayout() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jPanel1.add(label2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(24, 14, 70, 0), 14, 0));
jPanel1.add(textField1, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(18, 25, 0, 25), 173, 0));
jPanel1.add(scrollPane, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(22, 26, 0, 25), 0, 62));
jPanel1.add(label1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(18, 14, 0, 0), 15, 0));
jPanel1.add(label4, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(18, 14, 25, 36), 13, 0));
jPanel1.add(label3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(34, 14, 0, 0), 23, 0));
jPanel1.add(textField2, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(30, 22, 0, 25), 173, 0));
jPanel1.add(textField3, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(19, 23, 25, 25), 173, 0));
scrollPane.getViewport().add(editorPane1, null);
jPanel1.setBorder(BorderFactory.createLineBorder(Color.black));
jPanel1.setLayout(gridBagLayout1);
label1.setText("CustomerName:");
label2.setText("Current Address:");
label3.setText("PhoneNumber:");
label4.setText("Email ID:");
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
}
}***********************************************************************