• Post Reply Bookmark Topic Watch Topic
  • New Topic

TableModel / JTable question  RSS feed

 
Johny Doey
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

how can I listen for clicks on my columns? I have sorting methods and they work, but how can I listen for clicks on a certain column header?
It's probably something obvious I missed when reading through Sun's documentation?
 
Johny Doey
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, figured it out.

basically I did this:
made a global variable
private JTableHeader header;
implemented MouseListener.
then in my main method
header = tablename.getTableHeader();
header.addMouseListener(this);
then in mouseClicked method I just did this:
if (e.getX()<header.getHeaderRect(int columnNumber).getX())
execute code...
basically to reg a click on the first column I used columnNumber 1 since that is basically the far most right point of column 0. Probably it would be best to go a reverse order instead...
so:

or something like that. you get the gist.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!