Reputation: 17
I'm making a program where the text in a textbox or a label will change when I select a row in a table. Like for example, I have three rows with 1, 2 and 3 as the data respectively. When I click the second row, the textbox should output 2 as the text. If I click the third row, it should output 3.
What event should I use without clicking a button?
Upvotes: 0
Views: 293
Reputation: 11474
Use a ListSelectionListener
for events triggered when an item was selected in the list:
list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
// called when list selection changed
}
});
Detailed instructions and methods for ListSelectionEvent
are available here.
Upvotes: 1