请查看以下链接并尝试解决问题:
http://www.daniweb.com/software-development/java/threads/29263
如何在Java中实现带有水平滚动条的JTable
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
public class ScrollableJTable {
public static void main(String[] args) {
new ScrollableJTable();
}
public ScrollableJTable() {
JFrame frame = new JFrame("Creating a Scrollable JTable!");
JPanel panel = new JPanel();
String data[][] = {
{"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
{"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
{"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
{"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
{"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
{"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
{"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
{"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
{"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
{"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
{"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
{"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
{"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
{"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
{"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
{"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
{"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
{"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
{"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
{"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
{"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
{"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
{"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
{"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
{"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
{"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
{"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
{"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
{"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
{"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
{"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
{"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"}
};
String col[] = {"Roll", "Name", "State", "country", "Math", "Marks", "Grade"};
JTable table = new JTable(data, col);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JTableHeader header = table.getTableHeader();
header.setBackground(Color.yellow);
JScrollPane pane = new JScrollPane(table);
panel.add(pane);
frame.add(panel);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}