I have a swing layout with some labels and a jTable.
On the left side, I have the jTable, and on the right side I have the labels.
I want to set the page up as a master / detail page, where the jTable is the master, while the labels act as details.
I have found a way to get the index from the jTable – my question. What kind of listener can I use to tell if the user selects a row in the table?
You need to get the JTable’s selection model (using
getSelectionModel()) and add aListSelectionListenerto this model.Make sure to use
convertRowIndexToModelto convert the index of the selected row to an index in the table model: if the table is sorted or filtered, the view and model indices won’t be the same.