String interessen[]= {"aaaaaaa", "bbbbbbbb", "ccccccccc", "ddddddd"};
myList = new JList<>(interessen);
myList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if(!e.getValueIsAdjusting())
System.out.println(myList.getSelectedValue());
}
});
The code above shows what getValueIsAdjusting do, without these method an event may be called eg. two times (it depends of event).
Output without getValueIsAdjusting loop after clicking on some element of JList:
aaaaaaa
aaaaaaa
with loop:
aaaaaaa