日期:2014-05-20  浏览次数:20625 次

哪位朋友帮我看下这个SWING的DEMO哪里有问题,中间部分显示不正常
package com.sky;
import java.awt.*;

import javax.swing.*;

public class Demo3 extends JFrame{

//北部区域
JLabel jl1;

//南部区域
JPanel jp1;
JButton jb1,jb2,jb3;

//中部区域
JTabbedPane jtp;
JPanel jp2,jp3,jp4;
JLabel jl2,jl3,jl4,jl5;
JTextField jtf;
JPasswordField jpf;
JButton jb4;
JCheckBox jcb1,jcb2;

public static void main(String[] args) {
// TODO Auto-generated method stub
Demo3 demo3=new Demo3();
}

public Demo3()
{
jl2=new JLabel("QQ号码",JLabel.CENTER);
jl3=new JLabel("QQ密码",JLabel.CENTER);
jl4=new JLabel("忘记密码",JLabel.CENTER);
jl4.setFont(new Font("宋体", Font.PLAIN, 16));
jl4.setForeground(Color.blue);
jl5=new JLabel("<html><a href='www.qq.com'>申请密码保护</a></html>");
jl5.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
jtf=new JTextField(10);
jpf=new JPasswordField();
jb4=new JButton("按钮");
jcb1=new JCheckBox("隐身登录");
jcb2=new JCheckBox("记住密码");

jl1=new JLabel("北部区域");

jp1=new JPanel();
jb1=new JButton("按钮");
jb2=new JButton("按钮");
jb3=new JButton("按钮");

jtp=new JTabbedPane();
jp2=new JPanel();
jp3=new JPanel();
jp3.setBackground(Color.red);
jp4=new JPanel();
jp4.setBackground(Color.blue);

jtp.add("QQ号码", jp2);
jtp.add("手机号码", jp3);
jtp.add("电子邮箱", jp4);

jp2.setLayout(new GridLayout(3,3));

jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);

jp2.add(jl2);
jp2.add(jtf);
jp2.add(jb4);
jp2.add(jl3);
jp2.add(jpf);
jp2.add(jl4);
jp2.add(jcb1);
jp2.add(jcb2);
jp2.add(jl5);

this.add(jtf,BorderLayout.CENTER);
this.add(jl1,BorderLayout.NORTH);
this.add(jp1,BorderLayout.SOUTH);

//ImageIcon icon=new ImageIcon("bg.jpg");
//this.setIconImage(icon.getImage());
this.setSize(350, 240);
this.setTitle("QQ");
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

















------解决方案--------------------
this.add(jp2,BorderLayout.CENTER);
------解决方案--------------------
this.add(jtp,BorderLayout.CENTER);