为什么vector作的table不能显示表头!!
      JTable table;
   Vector title,col,row;
           row=new Vector();
           col=new Vector();
    title=new Vector();
    title.clear();
            title.add("sheng");
            title.add("city");
            title.add("miaoshu");
            while(rs.next()){
        row.clear();
        row.add(rs.getString(1));
        row.add(rs.getString(2));
        row.add(rs.getString(3));
          row.clone();
        col.add(row);
            }
      
       table=new JTable(col,title); 
       table.add(col,title);
                        container.add(table,BorderLayout.CENTER);
                       table.repaint();
    运行的结果只有表体,没有表头,请大家多多指教!!!谢谢!!!

解决方案 »

  1.   

    不要直接将JTable加到Panel里
    JScrollPane jsp = new JScrollPane();
    jsp.setViewportView(table);
    container.add(jsp,BorderLayout.CENTER);
      

  2.   

    谢了!!!!!不过,
    请问jsp.setViewportView实现的是什么功能呀??
      

  3.   

    Creates a viewport if necessary and then sets its view. Applications that don't provide the view directly to the JScrollPane constructor should use this method to specify the scrollable child that's going to be displayed in the scrollpane. For example: 
     JScrollPane scrollpane = new JScrollPane();
     scrollpane.setViewportView(myBigComponentToScroll);
     
    Applications should not add children directly to the scrollpane.
      

  4.   

    同jsp.getViewPort().setView(table)或jsp.getViewPort().add(table)
    也就是JTable必须加到JScrollPane中才能实现滚动(JList也是这样)并且显示表头