public class HIMSEmployeeSearch    extends JPanel implements  ActionListener{
      public int  IDint;
    public int  IDint2;
    public String YH_Name;
      public String SearchName;
        public  String Sex1;
        public  int age;
         public String  JG;
          public  String DZ;
           public  String phone;
               public  String bm;
               public  String zw;
                    public  String gj;
           public  String E_Mail;
             public  String nowTime1;    Label title=new Label("公司员工信息查询界面");
            TextField Searchtext=new     TextField (10);               JButton  updateButton1=new JButton("修改");
        JButton  SearchButton=new JButton("搜索");
              JButton delButton2=new JButton("删除");
               TextArea  textarea=new TextArea();
                 JTable table=new  JTable() ;Object a[][];public  HIMSEmployeeSearch  (){
          setLayout(null);     title.setFont(new java.awt.Font("SansSerif",1,30));
               title.setForeground(Color.red);
                  add(title);
为什么我设置布局为null时,面板是一片空白呢?什么组件都没显示。注意:class类中是extends JPanel 

解决方案 »

  1.   

    每个组件可以使用setBounds设置它在容器中的位置和大小
      

  2.   

    setLayout(null);后需要自己布置各组件的位置和大小。P.S. 最好不要混用 AWT和 Swing组件。
      

  3.   

      this.setVisible(true);
    永远不要忘了这句。
      

  4.   

    额,我忘记说了我已经有设置位置和大小,可是他还是默认FlowLayout布局,为啥不按我的setBounds布局呢?
      

  5.   

    搞定了,谢谢啊,不过我还想问一下class类中是extends JPanel 就用不了BorderLayout布局吗?
      

  6.   

    怎么搞定的啊? 我也碰到了同样的问题。
    可不可以发表看看。package Ex5_6;
    import java.*;
    import java.awt.*;import javax.swing.*;public class Null extends JFrame {
    private JLabel name1=new JLabel("学号");
    private JLabel name2=new JLabel("系别");
    private JLabel name3=new JLabel("地址");
    private JLabel name4=new JLabel("姓名");
    private JLabel name5=new JLabel("专业");
    private JButton Btn1=new JButton("添加");
    private JButton Btn2=new JButton("查询");
    private JButton Btn3=new JButton("退出");



    private JTextField t1=new JTextField();
    private JTextField t2=new JTextField();
    private JTextField t3=new JTextField();
    private JTextField t4=new JTextField();
    private JTextField t5=new JTextField();public Null(){
    JPanel jp=(JPanel)this.getContentPane();
    jp.setLayout(null);

    name1.setBounds(20, 30, 60, 30);
    name2.setBounds(20, 70, 60, 30);
    name3.setBounds(20, 110, 60, 30);
    name4.setBounds(160, 30, 60, 30);
    name5.setBounds(160, 70, 60, 30); t1.setBounds(90, 30, 60, 30);
    t2.setBounds(90, 70, 60, 30);
    t3.setBounds(90, 110, 140, 30);
    t4.setBounds(230, 30, 60, 30);
    t5.setBounds(230, 70, 60, 30);

    Btn1.setBounds(10, 210, 60, 30);
    Btn2.setBounds(100, 210, 60, 30);
    Btn3.setBounds(190, 210, 60, 30);



    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置缺省的关闭操作
    }public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(false);//是否设置与本地一样的样式
    Null multifrm=new Null();
    multifrm.setSize(500, 400);
    multifrm.setLocation(400,400);
    multifrm.setVisible(true);
    multifrm.setTitle("  ");
    }}
      

  7.   

                    jp.add(name1);
    jp.add(name2);
    jp.add(name3);
    jp.add(name4);
    jp.add(name5);
    jp.add(t1);
    jp.add(t2);
    jp.add(t3);
    jp.add(t4);
    jp.add(t5);
    jp.add(Btn1);
    jp.add(Btn2);
    jp.add(Btn3);
    现在知道了,原来粗心少了这个。