1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import java.awt.*; import javax.swing.*; public class TableDemoMVC extends JFrame{ TableDemoMVC(){ init(); } protected void init(){ Container ct; final String[] columnNames={"姓名","职位","电话","月薪","婚否"};
final Object[][] data={ {"王东","总经理","0191123823",new Integer(5000),new Boolean(false)}, {"李宏","秘书","0191123824",new Integer(3500),new Boolean(true)}, {"李瑞","开发","0191123825",new Integer(4500),new Boolean(false)}, {"赵新","保卫","0191123826",new Integer(2000),new Boolean(true)}, {"陈理","销售","0191123827",new Integer(4000),new Boolean(false)}, };
JTable table=new JTable(data,columnNames); this.setSize(new Dimension(500,230)); JScrollPane jp=new JScrollPane(table); ct=getContentPane(); ct.add(jp); } public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException{ try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (Exception e) { System.out.println("Look and Feel not set"); } TableDemoMVC frame=new TableDemoMVC(); frame.setVisible(true); } }
|