simple problem - jtable model
hello!
can anybody tell what's wrong with this code?
There is simple table model:
publicclass TableModel2extends AbstractTableModel{
private String[] columnNames;
private Object[][] data;
public TableModel2(JTable divTab,String [] subs){
columnNames=new String[10];
int rows=subs.length;
System.out.println("ROWS=="+rows);
for (int i=0;i<10;i++){
columnNames[i]=new String(""+i);
}
data=new Object [rows][10];
for (int i=0;i<rows;i++){
for (int j=0;j<10;j++){
data[i][j]=new Boolean(false);
}
}
}
publicint getColumnCount(){
return columnNames.length;
}
publicint getRowCount(){
return data.length;
}
public String getColumnName(int col){
return columnNames[col];
}
public Object getValueAt(int row,int col){
return data[row][col];
}
public Class getColumnClass(int c){
return getValueAt(0, c).getClass();
}
publicboolean isCellEditable(int row,int col){
if (col >< 1){
returnfalse;
}else{
returntrue;
}
}
publicvoid setValueAt(Object value,int row,int col){
System.out.println("Setting value at " + row +"," + col
+" to " + value
+" (an instance of "
+ value.getClass() +")");
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
When i repleace "rows" by e.g 4 everything is ok, but when there is value (not 0) that is length of subs table i always have 0 rows.. what's wrong with it?
Thank you for replies
Message was edited by:
polak

