I have a jlist which has some elements and works properly. Then I am trying to add the selected jlist elements to string list, but it wont show any results (no errors though). Whats wrong?
inal JList list = new JList(arraylist.toArray());
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JOptionPane.showMessageDialog(
null, list, "Select", JOptionPane.QUESTION_MESSAGE);
ListSelectionListener listSelectionListener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
String lstr = list.getSelectedValue().toString();
List<String> tolist = Arrays.asList(lstr);
System.out.println(tolist);
}
};
Updated: ( Fixed)
final ListSelectionListener listSelectionListener = new ListSelectionListener() {
public void valueChanged (ListSelectionEvent e) {
String lstr = list.getSelectedValuesList().toString();
System.out.println(lstr);
List<String> tolist = Arrays.asList(lstr);
System.out.println(tolist);
}
};
list.addListSelectionListener(listSelectionListener);
JOptionPane.showMessageDialog( null, list, "Select", JOptionPane.QUESTION_MESSAGE);