notamonopoly
November 15th, 2007, 05:08 PM
I am fairly new to Java and I've been struggling with using Swing components. I've learned a lot by reading the docs and following examples but I've hit a wall and it's time to ask some questions.
I have a jTable that has three columns, File name(String), File size(Long) and a Progress (JProgressBar). Ignore the Progress column for the moment, I'm simply trying to get the File size column sorted properly.
I've extended a AbstractTableModel and implemented a TableCellRenderer.
Since the default row sorter sorts everything as a string I made sure to return Long.class in the TableModel getColumnClass() for this column. I thought that would be sufficient but It was still sorting it as a string so I extended the TableRowSorter.
When I try to add data to the table it gives me a "java.lang.IndexOutOfBoundsException: Invalid range". So I've given up on the TableCellRenderer for the moment and went back to using the default.
I can provide example code if it helps but I mostly wanted to confirm that returning the appropriate class (Long) in the TableModel should cause the default table sorter to sort the column as a number and not a string.
Once I get that working I will tackle extending the TableRowSorter to use for the progress column.
Thank you
I have a jTable that has three columns, File name(String), File size(Long) and a Progress (JProgressBar). Ignore the Progress column for the moment, I'm simply trying to get the File size column sorted properly.
I've extended a AbstractTableModel and implemented a TableCellRenderer.
Since the default row sorter sorts everything as a string I made sure to return Long.class in the TableModel getColumnClass() for this column. I thought that would be sufficient but It was still sorting it as a string so I extended the TableRowSorter.
When I try to add data to the table it gives me a "java.lang.IndexOutOfBoundsException: Invalid range". So I've given up on the TableCellRenderer for the moment and went back to using the default.
I can provide example code if it helps but I mostly wanted to confirm that returning the appropriate class (Long) in the TableModel should cause the default table sorter to sort the column as a number and not a string.
Once I get that working I will tackle extending the TableRowSorter to use for the progress column.
Thank you