给你代码,你参考一下。
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class TableApp extends JFrame {
private String[] columns = { "name", "age", "email" };
public TableApp() {
JScrollPane scrollpane = new JScrollPane();
DefaultTableModel model = new DefaultTableModel(columns, 10);
JTable table = new JTable(model);
scrollpane.setViewportView(table);
add(scrollpane, BorderLayout.CENTER);
setSize(600, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new TableApp();
}
}