jPanel5.add(jScrollPane5, BorderLayout.CENTER);
jScrollPane5.getViewport().add(table, null);
这样子试试

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;public class SimpleTable {
         
        public SimpleTable() {
        
        JFrame f = new JFrame();
       
    Object[][] p=
      {
         {
            "甲座", "801", "李", "男", "801123", "汉", "11111"
         },
         {
            "甲座", "802", "孙", "男", " ", " ", " "
         },
         {
            "甲座", "803", "杨", " ", " ", " ", " "
         },
      };
      String[] n=
      {
         "楼号","房间号","用户姓名","性别","出生日期","民族","身份证号"
      };
            JTable table = new JTable(p, n);
            table.setPreferredScrollableViewportSize(new Dimension(550, 30));        //Create the scroll pane and add the table to it. 
            JScrollPane scrollPane = new JScrollPane(table);        //Add the scroll pane to this window.
            f.getContentPane().add(scrollPane, BorderLayout.CENTER);
        f.setTitle("Simple Table");
            f.pack();
            f.setVisible(true);
            
            f.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });    }    public static void main(String args[]) {
        
            SimpleTable b = new SimpleTable();
        }
    }
    测试通过!