svkvvenky
svkvvenky

Reputation: 1120

Related to ListSelectionListener

I used ListSelectionListener to listen the selection of a JTable to perform other task related with the selected item in the table. but why the following code executed twice at one selection in the beginning and many times times after that table is being updated?

 public void valueChanged(ListSelectionEvent e) 
    System.out.println(tablelist.getSelectedIndex());       
 }

Upvotes: 1

Views: 205

Answers (1)

mKorbel
mKorbel

Reputation: 109813

because ListSelectionListener from ListSelectionModel interface always firing two events

int firstIndex = e.getFirstIndex();
int lastIndex = e.getLastIndex();

everything in the Oracle tutorial

Upvotes: 3

Related Questions