ciao!
allora, sto cercando di riempire una JTable con un oggetto specifico.
questo il table model:
codice:
import javax.swing.table.DefaultTableModel;
public class MyTableModel extends DefaultTableModel {
public MyTableModel(Object[][] data, String[] col) {
super(data, col);
}
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
}
questo l'oggetto Record:
codice:
public class Record {
private String nome;
private String tipo;
private String path;
public Record(String nome, String tipo, String path) {
this.nome = nome;
this.tipo = tipo;
this.path = path;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
@Override
public String toString() {
return getNome() + " " + getTipo() + " " + getPath();
}
}
questo il metodo che riempie la lista:
codice:
public ArrayList<ArrayList<Record>> scanDir(File dir) throws IOException {
ArrayList<ArrayList<Record>> list = new ArrayList<>();
File[] files = dir.listFiles();
Arrays.sort(files, new MyComparator());
for (File file : files) {
ArrayList<Record> records = new ArrayList<>();
Record record = new Record(file.getName(), new Tika().detect(file), file.getAbsolutePath());
records.add(record);
list.add(records);
}
return list;
}
questo come riempio la JTable:
codice:
ArrayList<ArrayList<Record>> list = utils.scanDir(dir);
list.stream().forEach((map) -> {
((MyTableModel) table.getModel()).addRow(map.toArray());
});
quello che succede è che viene valorizzata solo la prima colonna.
penso che il problema sia l'override delmetodo toString().
ma come posso fare per mettere ogni campo nella colonna specifica??