Forums Register Login

JTable selection listener doesn't listen to column changes

+Pie Number of slices to send: Send


This is a basic implementation of ListSelectionListener with cell selection enabled, so a single column is selected whenever a row is selected, and together the selections determine a cell selection, right?
When nothing in the cell is selected, and then a cell is selected by clicking on it, it triggers a ListSelectionEvent, as it should.
After that, when a cell in a different row on the same table is selected, it triggers an event.
However, when a cell on the same row and a different column is clicked on, or moved to by right or left arrow buttons, it does not trigger a ListSelectionEvent. I think it should change because the column selection does change even though the row selection does not.
How can I make the program listen to changes in column selection, when the row selection does not change?
+Pie Number of slices to send: Send
Hint: a JTable's TableColumnModel has its own ListSelectionModel.
+Pie Number of slices to send: Send
You have to add two listeners:

ListSelectListenerObj=new ListSelect()
table.getSelectionModel().addListSelectionListener(ListSelectListenerObj);
table.getColumnModel().getSelectionModel() .addListSelectionListener(ListSelectListenerObj);
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 9898 times.
Similar Threads
Related to JTable( Switching between Row Selection)
Using cell editors in JTable
jtable
Notifying listeners of changes in jtable cell selection
JTable ListSelection problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:21:43.