import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; //================================================= // File Name : JTable_demo //------------------------------------------------------------------------------ // Author : Common //主类 //Function : JTable_demo public class JTable_demo { public static void main(String[] args) { // TODO 自动生成的方法存根 JFrame frame = new JFrame("窗体"); //定义窗体 String[] titles = {"姓名","年龄","性别","成绩","是否及格"}; Object[][] userInfo = {{"张三",22,"男",99,true},{"张三",22,"男",99,true} ,{"张三",22,"男",99,true},{"张三",22,"男",99,true},{"张三",22,"男",99,true}}; JTable table = new JTable(userInfo,titles); JScrollPane scr = new JScrollPane(table); frame.add(scr); frame.setSize(330,100); frame.setVisible(true); frame.addWindowListener(new WindowAdapter(){ //加入事件监听 public void windowClosing(WindowEvent arg0) { //窗口关闭时触发,按下关闭按钮 // TODO 自动生成的方法存根 System.out.println("windowClosing-->窗口关闭"); System.exit(1); } }); } }