请问JAVA Swing组件JTable 怎么用Vector构造

2022-08-03 娱乐 149阅读
public static void main(String[] args) {

Student s1 = new Student("张三", "001", 0);
Student s2 = new Student("李四", "002", 1);
Student s3 = new Student("王五", "003", 0);

Vector row1 = new Vector();
row1.add(s1.getName());
row1.add(s1.getNumber());
row1.add(s1.getAbsentTimes());

Vector row2 = new Vector();
row2.add(s2.getName());
row2.add(s2.getNumber());
row2.add(s2.getAbsentTimes());

Vector> studentData = new Vector>();
Vector columnNames = new Vector();

studentData.add(row1);
studentData.add(row2);

columnNames.add("姓名");
columnNames.add("编号");
columnNames.add("缺考次数");

JTable table = new JTable(studentData, columnNames);

JFrame f = new JFrame();

JScrollPane scrollPane = new JScrollPane(table);
f.getContentPane().add(scrollPane, BorderLayout.CENTER);
f.setVisible(true);
f.setSize(500, 500);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com