When my table updates itself with new data, it calls prepareRenderer
. This is by default what a JTable does when updated. However, when my program calls the prepareRenderer method, it is giving it a null TableCellRenderer in it's arguments. Therefore I get a null pointer exception.
dataTable = new javax.swing.JTable() {
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
return super.prepareRenderer(renderer, row, column);
}
};
That is how I declare it. The @Override isn't even really needed. I put it there so I can put a breakpoint in it so I could see it was actually firing and what the arguments' values were. For whatever reason, when java called this prepareRender method, it gives a null value for the TableCellRenderer argument. Why is it doing that and how do I fix it? I get nothing on the screen because of the NPE.
The issue was in my tablemodel. Specifically, the getColumnClass
method was not returning anything (null's only) because of how I was coding the return. If the getColumnClass method does not work, the tablecellrender fails because it doesn't know how to show the data.