문제

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 JLists 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;

enter image description here

도움이 되었습니까?

해결책

A JTable works like a JList because it also has a ListSelectionModel. So you would just use:

table.getSelectionModel().addListSelectionListener(...);

다른 팁

ListSelectionListener works on SelectionModel and since our table also has a selectionModel therefore we cann apply it on JTable as well.

tablename.getSelectionModel().addListSelectionListener(argument);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top