I am new at programming and am working on my first school assignment. I have written a gui that accepts input and outputs data in a jtable added to a jpaddedpane. When the table first appears it shows all the correct data. But when I enter new input the table won′t update. I am alsmot positive the problem lies with my implementation of AstractTableModel. Can someone please take a look and correct it for me asap? Thanks in advance.
ps. nh, vh, hNam, proc_1 and proc_ are integer, string, integer, string and string arrays respectively. They hold the data to be displayed in the table.
public class TableModel extends AbstractTableModel {
int numRows;
String colNames[] = { "NH", "Horse Names", "VH",
"Proc. I", "Proc. II" };
Object[][] obj;
TableModel() {
super();
numRows = fnh;
obj = new Object[fnh][5];
for( int i = 0; i < fnh; i++ ) {
for ( int j = 0; j < 5; j++ ) {
if ( j == 0 )
obj[i][0] = (Integer)nh[i];
else if ( j == 1 )
obj[i][1] = (String)hNam[i];
else if ( j == 2 )
obj[i][2] = (Integer)vh[i];
else if ( j == 3 )
obj[i][3] =(String)proc_1[i];
else
obj[i][4] =(String)proc_2[i];
}
}
}
@Override
public int getRowCount() {
return numRows;
}
@Override
public int getColumnCount() {
return 5;
}
@Override
public String getColumnName( int c ) {
return colNames[c];
}
@Override
public Object getValueAt( int r, int c ) {
if ( c == 0 )
return nh[r];
else if ( c == 1 )
return hNam[r];
else if ( c == 2 )
return vh[r] ;
else if ( c == 3 )
return proc_1[r];
else
return proc_2[r];
}
@Override
public boolean isCellEditable( int r, int c ) {
return true;
}
public void setValueAt( Object[][] value, int r, int c ) {
value = obj;
fireTableCellUpdated( r, c );
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…