how to sort the JTable column by default
Hi,
How to sort a specific column in JTable by default, if required I can provide the Column Name.
I got a code for sorting JTable values, if we mouse click on a column, but I need it for a spcific column where in it should get defaultly sorted at loading time itself.
any snippets or suggestion plz.
Regards,
Ravi
# 1
> Hi,
>
> How to sort a specific column in JTable by default,
> if required I can provide the Column Name.
>
> I got a code for sorting JTable values, if we mouse
> click on a column, but I need it for a spcific
> column where in it should get defaultly sorted at
> loading time itself.
the JTable values are associated: a line is corresponding to a set of values so it is a non
sens to want to sort a specific column!
> any snippets or suggestion plz.
>
> Regards,
> Ravi
# 2
i want to sort the complete data of JTable, but for this initially we have to choose a column right ?
In that view i was saying, if you want i can provide the column name.
so that base on that column complete JTable values has to get sorted.
I have a solution for this problem, i.e., before passing the column names and values, we have to sort the values(on a wanted column) and then pass values array object to the JTable Constructor.
But i want to know whether we have any predefined functionality exists to achive this functionality.
for more clarity :
The values that i pass to the JTable constructor are like below :
BBombay
ZZebra
AApple
The JTable should display this data in the below manner :(sorting the values based on first column)
AApple
BBombay
ZZebra
This is my requirement. How to achive this. Is there any functinality already available with JTable class or any other classes or we ourself mannually sort the values and need to pass that array as values to JTable Constructor.
Hope i am clear.
Need help in this regard.
# 3
> I got a code for sorting JTable values, if we mouse click on a column,
Then look at the source code. A MouseListener is added to the table header. When you click on the header the mouse point is converted to a column and a method is invoked to sort that column.
So all you have to do is manually invoke the method that does the sorting once you look at the source code to determine the method name.