Reputation: 308
In my Table Model I have an ArrayList<ArrayList<Object>>
which contains my data.
The data has been read in from a .csv file, each record is of the form:
7.68573749,-8.551567,21,276,AUD,AAA,7.224,1002,250,AUD Eurobonds Secondary,01/02/1996,T00001
I tried to read in each cell with the appropriate type but, for example, 7.68573749
would not read in with the scanner method nextDouble()
. So everything is read in as String
by default.
So my TableModel extends AbstractTableModel
, and I have overridden the getColumnClass
method, using an array of Class types hardwired in, with the getColumnClass(int col)
returning the appropriate Class etc
Unfortunately, I still cannot set each cell to be the appropriate type as I get errors: cannot render Object as Number, when trying to use Double.Class.
I can however set everything to be either String or Integer.
But even with that, the AutoRowSorter
still sorts every column by String only.
I can post code, but there is a lot of code and I can provide it when asked specifically what is needed.
Any help would be great, thanks, the ultimate goal here is to be able to sort the table data correctly
Upvotes: 1
Views: 357
Reputation: 606
Try to set column's Datatype as double , then convert the String numbers into Double using Double.valueOf() and simultaneously insert it into the JTable
example
for(int i=0;i<ss.length;i++)
{
table_model_object.addRow(i,Double.valueOf(ss[i]);
}
Upvotes: 1