日期:2014-05-20 浏览次数:20840 次
import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; public class TableInsertTest extends JFrame { private JTable table = new JTable(); public TableInsertTest() { TableModel dataModel = new DefaultTableModel() { public int getColumnCount() { return 10000; } public int getRowCount() { return 10; } @Override public Object getValueAt(int row, int column) { return row * column; } }; this.table = new JTable(dataModel); this.table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); this.table.getTableHeader().setPreferredSize( new Dimension(this.table.getTableHeader().getPreferredSize().width, 30)); this.table.updateUI(); JScrollPane scrollpane = new JScrollPane(this.table); Container contentPane = this.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(scrollpane, BorderLayout.CENTER); } /** * @param args */ public static void main(String[] args) { TableInsertTest frame = new TableInsertTest(); frame.setVisible(true); frame.setSize(300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }