Java 图形用户界面-表格组件
/** 作者:wwj 日期:2012/4/15 功能:创建一个表格 **/ import java.awt.*; import javax.swing.*; public class JTb1 extends JFrame { JTable table; public JTb1() { super("带有表格组件的窗口"); setSize(400,300); try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){} Container c=getContentPane(); //创建表值 Object[][]data={ {"082520","张平","03A01",80,90,95,(80+90+95)}, {"082521","李红","03A02",88,90,90,(88+90+90)} }; String[] rowName={"学号","姓名","班级","数学","体育","英语","总分"}; table=new JTable(data,rowName);//创建表格对象 c.add(new JScrollPane(table)); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String []args) { JTb1 d=new JTb1(); } }