我有这堂课:
public abstract class Directory {
protected int id;
protected File path;
protected LinkedList<Filter> filters;
protected LinkedList<File> files;
protected int wildcard;
public static int numCols = 3;
/* other things */
}
我写了这个表模型:
public class DirectoryListTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
private LinkedList<Directory> datalist;
private String[] columnNames= {"ID", "Directory", "Wildcard", "Filters"};
public DirectoryListTableModel(){
}
public void setDatalist(LinkedList<Directory> temp){
this.datalist = temp;
}
public void showElement(){
fireTableRowsInserted(this.datalist.size()-2,this.datalist.size()-2);
}
public LinkedList<Directory> getDatalist(){
return (LinkedList<Directory>) this.datalist.clone();
}
@Override
public String getColumnName(int column) {
return this.columnNames[column];
}
@Override
public int getColumnCount() {
return Directory.numCols;
}
@Override
public int getRowCount() {
return this.datalist.size();
}
@Override
public Object getValueAt(int row, int col) {
Directory temp = this.datalist.get(row);
switch(col){
case 0:
return temp.getId();
case 1:
return temp.getPath();
case 2:
return temp.getWildcard();
default:
return null;
}
}
}
正如您所看到的,我有一个LinkedList<Filter>
,我想将其显示为一个简单的字符串。我怎么能这样做?
答案 0 :(得分:2)
e.g:
case 3:
return temp.getFilters().toString();
注意: