日期:2014-05-20 浏览次数:20619 次
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class xxx{
public xxx(){
JFrame f=new JFrame();
Object[][] playerInfo={
{"小猪",new Integer(66),new Integer(32),new Integer(98),new Boolean(false)},
{"小猪",new Integer(82),new Integer(69),new Integer(128),new Boolean(true)},
{"小猪",new Integer(96),new Integer(69),new Integer(128),new Boolean(true)},
{"小猪",new Integer(82),new Integer(78),new Integer(128),new Boolean(true)},
};
String[] Names={"姓名","语文","数学","总分","及格"};
Vector<Object> v = new Vector<Object>();
Vector<Object> v1 = new Vector<Object>();
v.add(playerInfo);
v1.add(Names);
JTable table=new JTable(v,v1);//这一步错了。
table.setPreferredScrollableViewportSize(new Dimension(550,30));
JScrollPane scrollPane=new JScrollPane(table);
f.getContentPane().add(scrollPane,BorderLayout.CENTER);
f.setTitle("Simple Table");
f.setVisible(true);
f.pack();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args){
xxx b=new xxx();
}
}