import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Demo extends JFrame{
public Demo(){
String[] lie = {"ID","课程名","教师","职位"};
String[][] hang = new String[2][4];
hang[0] = new String[]{"1","高数","毕","不明"};
hang[1] = new String[]{"2","c语言","星哥","不明"};
DefaultTableModel defaultTableModel = new DefaultTableModel(hang,lie);
JTable jTable = new JTable(defaultTableModel);
getContentPane().add(jTable.getTableHeader(), BorderLayout.NORTH);//添加表头进容器
Container fContainer = getContentPane();
fContainer.add(jTable);
setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口关闭规则
setBounds(100,200,300,300);//设置窗口初始大小
}
public static void main(String[] args) {
new Demo().setVisible(true);//窗口可见
}
}