我有这堂课:
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>
,我也想将其显示为简单的字符串。我怎样才能做到这一点?