Sorry for the lolcat title, but seriously I don't know what the best approach would be.
I'm working with a table model. In the data I have a String, 2 Integers, and 1 Boolean column.
The Boolean and one of Integer columns CAN have empty values.
When I'm populating the data I'm setting the default values of the Boolean to false and the integer to null like so:
Symptom of problem:
The records that DO have a value, JTable treats them like a string and aligns them to the left. Yuck!
I should mention I have overridden the AbstracTableMod el's getColumnClass( ) like this:
This method is called by JTable's Cell Render..er. As you can see I'm creating an int and returning it.
it works, but again Yuck! and what if there's an empty record in the String column. The cell render will treat it as an int.
If I could somehow declare my default value as an empty int that would be great and I can change the above method to just the return line:
return getValueAt(0, c).getClass();
and be done with it!
My other option is to evaluate c (the column index) and find which column it is and hard code the default type of that column, but again what if I reorder my columns or drop columns in the future? I'd rather not have this mess to maintain.
In short, can I have my cake and 'not' eat it too?
: )
Thanks for any feedback guys!
Dan
I'm working with a table model. In the data I have a String, 2 Integers, and 1 Boolean column.
The Boolean and one of Integer columns CAN have empty values.
When I'm populating the data I'm setting the default values of the Boolean to false and the integer to null like so:
Code:
result[ri][0] = sdtSrvc.getServiceId(); result[ri][1] = " "+sdtSrvc.getCallTag(); result[ri][2] = (mapSrvc != null) ? mapSrvc.getCableID() : null; //<--------- Empty Integer Needed Here instead of null result[ri][3] = (mapSrvc != null) ? mapSrvc.getEnabledFlag() : false; result[ri][4] = sdtSrvc.getTransportStreamId();
The records that DO have a value, JTable treats them like a string and aligns them to the left. Yuck!
I should mention I have overridden the AbstracTableMod el's getColumnClass( ) like this:
Code:
@Override public Class getColumnClass(int c) { Object val = getValueAt(0, c); if(val == null) { Integer scrap = 0; return scrap.getClass(); } else { return getValueAt(0, c).getClass(); } }
it works, but again Yuck! and what if there's an empty record in the String column. The cell render will treat it as an int.
If I could somehow declare my default value as an empty int that would be great and I can change the above method to just the return line:
return getValueAt(0, c).getClass();
and be done with it!
My other option is to evaluate c (the column index) and find which column it is and hard code the default type of that column, but again what if I reorder my columns or drop columns in the future? I'd rather not have this mess to maintain.
In short, can I have my cake and 'not' eat it too?
: )
Thanks for any feedback guys!
Dan
Comment