package table;
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) {
JFrame jf = new JFrame("测试窗口");
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new BorderLayout());
Object[] columnNames = {"姓名", "语文", "数学", "英语", "总分"};
Object[][] rowData = {
{"张三", 80, 80, 80, 240},
{"John", 70, 80, 90, 240},
{"Sue", 70, 70, 70, 210},
{"Jane", 80, 70, 60, 210},
{"Joe", 80, 70, 60, 210}
};
JTable table = new JTable(rowData, columnNames);
panel.add(table.getTableHeader(), BorderLayout.NORTH);
panel.add(table, BorderLayout.CENTER);
jf.setContentPane(panel);
jf.pack();
jf.setLocationRelativeTo(null);
jf.setVisible(true);
}
}

jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);