2

I have a JTable with column headers. When I click on a column header the data gets sorted. This is the default sort behavior.

The thing is that I need to remember the last column the user clicked to sort. Anyone knows which listener I need to implement in order to catch the column name that user clicked for sorting on the JTable?

The code is already implemented and I'm new to Swing. I just need to add that extra functionality. So any clues will be helpful.

Thanks in advance.

2 Answers 2

1

You can add a MouseListener to the JtableHeader. Then you just use the columnAtPoint(...) method to determine when a column is clicked.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for that answer. So now how can I manually sort a column that will simulate a user clicking on a column? I couln't find a method that will do that. Should I manually fire a MouseClicked event?
see the sort() method of the DefaultRowSorter.
1

Use Swing-X components, there is a JXTable which is more powerful than JTable.

1 Comment

Although this is a good suggestion, it doesn't answer the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.