-
table column sort
I want to find out if a column is sorted Ascendingly using the following line, but it keeps giving me a Null Pointer exception. Does anyone know why? Or if you know of another way to find out how a tabal column is sorted?
Thanks.
if (Table.getRowSorter().getSortKeys().get(0).getSort Order().equals(SortOrder.ASCENDING))
-
probably because one of the objects is null.
- maybe table doesn't have a row sorter
- maybe row sorter doesn't have keys
- maybe the first key doesn't have sort order
split your one line into separate assignments and you'll at least know what exactly is failing...
-
When a JTable is created it doesn't create a row sorter automaticall?
-
good question. if you split up your line like I'm suggesting, you'll find the answer to that.
-
You are obsolutely correct. The row sorter is null.
So now my question is, if this table doesn't have a road sorter, can I still be able to find out how the column is sorted?
-
taking a look at How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components), i think all you have to do is say
Code:
table.setAutoCreateRowSorter(true);
which indeed seem kind of crooked... hope that works.
-
The table I am dealing with is an existing table which I don't want to make any changes if I don't have to.
Without a rowsorter, can I still be able to find out how the columns are sorted?
-
-
If I am going to add a row sorter...
The following table model "DtableModel"extends "AbstractTableModel" (old code)
DTableModel model = new DTableModel(columnDefinitions);
I added the following:
final TableRowSorter<DTableModel> sorter = new TableRowSorter<DTableModel>(model);
this.indicationTable.setRowSorter(sorter);
The statement "this.indicationTable.setRowSorter(sorter);" gave me an exception.
Do I have to use DefaultTableModel instead of my own (DTableModel)?