I have a JTable
with contact names in. On selecting a row from this table a second table is filled with that person's primary phone number and email address. At the moment I am using a custom MouseListener
to check when people are clicking on a row in the first table, but I also want them to be able to scroll through the list with their keyboard.
I have used ListSelectionListener
on JList
s in the past and vaguely remember someone saying that ListSelectionListener
could be used on a JTable, but have been unable to find anywhere explaining how.
So, my question is.. Can ListSelectionListener
(or similar) be used on a JTable
? If so, how?
Image below - The image's Table is blurred so it probably doesn't help much;
A JTable works like a JList because it also has a ListSelectionModel. So you would just use:
table.getSelectionModel().addListSelectionListener(...);