Java GUI应用程序,将数据从列表<objects>加载到Jtable. [英] Java GUI aplication, load data to Jtable from a list<objects>
问题描述
Java GUI应用程序,将数据从列表加载到Jtable 我找到了以下链接,但没有找到答案: http: //docs.oracle.com/javase/tutorial/uiswing/components/table.html
Java GUI aplication, load data to Jtable from a list i have found the following link but i haven't found an answer: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
请有人给我一个例子,我应该怎么做. 我的对象有5个字段:名称,等级,薪水,出生年份,性别 并且列表是从文件中读取的,所以我不知道列表会有多少个对象. 我在netbeans工作.
please can someone gice me an example how should i do it. my objects have 5 fields:Name,Grade,Salary,BirthYear,Sex and the list is readed from a file so i dont know how many ojects will the List have. I am working in netbeans.
推荐答案
The tutorial you linked to has an example: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data. You should be able to adapt it to a List<Employee>
easily:
public int getRowCount() {
return list.size();
}
public int getColumnCount() {
return 5;
}
public Object getValueAt(int row, int col) {
Employee employee = list.get(row);
if (col == 0) {
return e.getName();
}
else if (col == 1) {
return e.getGrade();
}
...
}
这篇关于Java GUI应用程序,将数据从列表<objects>加载到Jtable.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!