views:

142

answers:

1

Is there any way to detect a cell selection change in a JTable? I've found documentation for detecting a row change using ListSelectionListener but it doesn't seam to work when changing selection on the same row. I'm using JTable to render a simple schedule.

Maybe I should use a different component?

+2  A: 

No, the right component for showing tabular data is JTable.

You want to add a listener to the TableModel that's underneath the table. That will fire off events whenever data changes. You get it out of JTable, unsurprisingly enough, by calling getTableModel().


Update

Oh wait, I think I misunderstood you. You're not interested in data changes but column selection changes.

JTable has a method called columnSelectionChanged; its documentation says it's called by TableColumnModelListener, which leads me to believe that what you want to do is getColumnModel() and use the addColumnModelListener() method of that to listen for column selection changes.

Carl Smotricz