tags:

views:

42

answers:

2

I need to store a mouse click event whenever a user clicks on a table column for sorting.

I'm basically saving the MouseEven:

public void mouseClicked(MouseEvent e_)

I store e_ on a global variable so later I can fire that same event and sort the table to the previous user sort action.

But when I manually fire the previous stored mouse event the table does not get sorted.

Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(_mouseEvent);

So basically this is how I want it to work. User clicks on a JTable column for sorting. I store the created MouseEvent on a global variable. When the JTable gets re-created, I need it to be set to the previous sort action.
This is why I need to re-fire the stored MouseEvent but its not working. Any ideas?

A: 

See the sort() method of the DefaultRowSorter.

camickr
A: 

It has nothing to do with mouse event. You have to store the state of your row sorter. Take a look at RowSorter API. You can retrieve and restore this state by using getSortKeys() and setSortKeys() methods. Obviously can get RowSorter from your table using getRowSorter()method.

Hope it makes sense.

eugener
Thanks, it makes sense. I'll give it a try.
Marquinio
Yup that did the trick thanks.
Marquinio