JTable method calling issue
I had an interesting observation with my JTable implmentation: The "getColumnCount" method was called many times (likely to be equal to the number of columns) when a JTable is rendered. Similarly, the "getRowCount" method was called many times as well. Interestingly, when I scroll the table, only "getRowCount" was called together with "getValueAt". "getColumnCount" was no longer called after the initiation of JTable. I am not sure whether this is normal behavior of JTable and would appreciate any comment and help.
Here is a sample of the code ( did not paste in all the code but hopefully it is enough for you to help me :-) ).
Thanks a lot!
TableModel dataTableModel = new AbstractTableModel() {
public int getColumnCount() {
int cCount = 20;
System.out.println("column count: "+ cCount);
return cCount;
}
public int getRowCount() {
int rCount = 20;
System.out.println("row count: "+ rCount);
return rCount;
}
public Object getValueAt(int row, int col) {
if (col==0){
cellValue="A";
}
else {
cellValue="B";
System.out.println("cell values at row "+row+" and column "+col+" is: "+cellValue);
}
return cellValue;
}
}
JTableHeader jTableHeader1;
jTable1 = new JTable(dataTableModel) {
public Dimension getPreferredScrollableViewportSize() {
return new Dimension(20 * getModel().getColumnCount(), 20 * getModel().getRowCount());
}
public boolean getScrollableTracksViewportWidth() {
return false;
}
};

