package ChatExtends;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.*;
public class LoginWindow extends JFrame {
public void Load() {
this.setName("Login");
this.setLayout(null);
this.setSize(600,600);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container ct = this.getContentPane();
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
jp1.setSize(600, 150);
jp2.setBounds(0,150,550,300);
GridLayout gy = new GridLayout(2,1,5,5);
jp2.setLayout(gy);
Font f = new Font("Blackletter",Font.ITALIC,100);
JLabel name = new JLabel("ChatW");
name.setFont(f);
name.setBounds(100,300,600,300);
name.setForeground(Color.blue);
name.setVisible(true);
jp1.add(name);
JLabel l = new JLabel();
ImageIcon ic1 = new ImageIcon("images/login.png");
l.setIcon(ic1);
//l.setBounds(0, 100, ic1.getIconWidth(), ic1.getIconHeight());
l.setVisible(true);
JTextField text1 = new JTextField(15);
//text1.setBounds(0, 100, 200, 100);
text1.setVisible(true);
JLabel l1 = new JLabel();
ImageIcon ic2 = new ImageIcon("images/lock.png");
l1.setIcon(ic2);
//l1.setBounds(0,300,ic2.getIconWidth(),ic2.getIconHeight());
l1.setVisible(true);
JPasswordField jf = new JPasswordField();
//jf.setBounds(50,300,200,100);
jp2.add(l);
jp2.add(text1);
jp2.add(l1);
jp2.add(jf);
jp2.setVisible(true);
this.add(jp1);
this.add(jp2);
this.setVisible(true);
ct.add(this);
ct.add(jp1,"North");
ct.add(jp2,"South");
}
}
为什么设置了GribLayout布局后label顶出了这么长呢?