Hej :)
Mam ArrayListe ktora chce wyswietlic w JTable.
Lista ma takie kolumny:
Numer Faktury|numer ID|imie|nazwisko|miejscowosc|
moj problem polega na tym ze jeden z elementow mojej listy - numer faktury to nie jest zaden prymityw czy tez klasa opakowań prymitywów, lecz obiekt mojej wlasnej klasy Nr Faktury ktora wyglada tak:
public class Nr_fakt implements Comparable <Nr_fakt>{
Integer numer;
Integer rok;
Nr_fakt(Integer a, Integer b) {
numer =a;
rok = b;
}
public Integer getNumer() {
return numer;
}
public Integer getRok() {
return rok;
}
I teraz gdy w ArrayLiscie mam obiekty Nr_fakt i chce go wyswietlic w JTable gdzie mam w Table Model:
class MyTabelModel extends AbstractTableModel {
private String[] columnNames = {"Numer Faktury", "numer ID","imie","nazwisko","miejscowosc"};
private ArrayList dane = null;
public MyTabelModel(ArrayList l) {
this.dane = l;
}
public MyTabelModel(){}
public int getRowCount() {
if(this.dane != null){
return this.dane.size();
}
else
return 0;
}
public int getColumnCount() {
return this.columnNames.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Class getColumnClass(int column) {
Class returnValue;
if ((column >= 0) && (column < getColumnCount())) {
returnValue = getValueAt(0, column).getClass();
} else {
returnValue = Object.class;
}
return returnValue;
}
public Object getValueAt(int row, int col){
p = dane.get(row);
switch(col){
case 0: return p.getNR_FAKT();
case 1: ...
...
to w Tabeli wyswietla mi to jako: Nr_Fakt@gfd4543 i takie rozne znaczki...
Dodam ze chce posortowac wg. tego numeru faktury i implementuje sobie metode CompareTo ktora wydaje mi sie ze działa: sprawdzalem w ten sposob ze przy getValueAt dodalem linijke:
System.out.println(getNumer()+"|"+getRok());
I gdy w Jtable klinalem na nazwe kolumny w outpucie wyswietla mi te dane w sposob posortowany, natomiast ja chce uzyskac taki widok w samej Tabeli, tzn zamiast tych '@c543hk' cyferek chce miec tam ten numer faktury wyswietlony tak: numer|rok.
Jesli w returnie wpisze getNumer()+"|"+getRok() to juz mi nie dziala sortowanie...
jakies pomysly ?