Your current code sets the selected column index before any mouse click has been performed:
So it shouldn't be surprising that the only output here is -1. But further, when you click on a column header, afaik, you don't select a column, so even if the getSelectedColumn() call were placed inside of the mouseClicked method, it still won't work. Perhaps what might work better is to call JTableHeader's columnAtPoint method like so:
Also, I personally usually prefer to act on mousePressed and not mouseClicked.
Joined: Jan 06, 2010
Joined: Feb 23, 2007
jhon max wrote:thank you.!
You're welcome and also a caveat: I'm about 90% sure of my answer, but since I'm not a pro, keep an eye on this thread. Usually if the pros see something amiss in my rec, they'll correct it.