>>
The JTable has a method, setAutoResizeMode(int), that defines the resize policy based on 5 constants, also defined in JTable :AUTO_RESIZE_OFF, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_SUBSEQUENT_COLUMNS,
AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_ALL_COLUMNSAUTO_RESIZE_OFF will disable all resizing and enable the horizontal scroll bar of the parent JScrollPane. 

解决方案 »

  1.   

    (参考)
    import javax.swing.*;
     import java.awt.event.*;
     import java.awt.*;
     import java.io.*;
     import java.util.*; public class DataFileTable extends JPanel {
       public DataFileTable(String dataFilePath) {
         JTable table;
         DataFileTableModel model;
         Font f;     f = new Font("SanSerif",Font.PLAIN,24);
         setFont(f);
         setLayout(new BorderLayout());     model = new DataFileTableModel(dataFilePath);     table = new JTable();
         table.setModel(model);
         table.createDefaultColumnsFromModel();     JScrollPane scrollpane = new JScrollPane(table);
         add(scrollpane);
         }  public Dimension getPreferredSize(){
         return new Dimension(400, 300);
         }
         
      public static void main(String s[]) {
         JFrame frame = new JFrame("Data File Table");
         DataFileTable panel;
             
         panel = new DataFileTable("customers.dat");     frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         frame.setForeground(Color.black);
         frame.setBackground(Color.lightGray);
         frame.getContentPane().add(panel,"Center");
             
         frame.setSize(panel.getPreferredSize());
         frame.setVisible(true);
         frame.addWindowListener(new WindowCloser());
         }
      } class WindowCloser extends WindowAdapter {
      public void windowClosing(WindowEvent e) {
        Window win = e.getWindow();
        win.setVisible(false);
        System.exit(0);
         }
     }
      

  2.   

    用AbstractTableModel是因为需要定制表格,这样才能够灵活地使用。defaultTableModel不够灵活
      

  3.   

    谢谢skyyoung(路人甲)兄 和 xegg(闲蛋) 兄,先。
    我try 一下!经常看见skyyoung(路人甲)兄的回复,也代别的兄弟感谢你!!每叠必给分
      

  4.   

    应该将Table放在ScrollPanel中,这样会自动出现滚动条的
      

  5.   

    不好意思,没看清你的题目就回答了。
    你可以试一试table类的方法:
    table.setShowVerticalLines(true);
    table.setShowHorizontalLines(true);
      

  6.   

    谢谢各位兄弟:
    问题已解决,
    必须设置:setLayout(new BorderLayout());can not use default Layout FlowLayout !!