Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JTable with JButtons in header

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted a simulare question in the general Java forum before I relized that this one was out there but here is what I am trying to do...

So the situation is this. I build a jtable dynamically from data I grabbed out of a database. Now I want to have the header tags do a sort(sorting being another problem) when a column is clicked. I do not know how to tell which column is clicked. Here is the snippet of code which I was working on for the eventListener

The print statement returns -1 each time which means that none of the 9 columns were selected. Not sure how to do this. Please help and thanks.

P.S. I know there is the sortable table on the sun website and I have played around with that but I am not sure how it is manipulating the data and so I wanted to do it myself when i did a button click. Down the road I would also need to figure out how to select a specific row but for now some button help would be great!
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change your MouseClicked method to include columnAtPoint, not getSelectedRow.

Here is a code fragment...

 
Kevin Hamrick
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeff,
That was exactly what I needed. It worked great.
 
crispy bacon. crispy tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic