Wednesday, 2 October 2013

Getting the elements selected of a jlist into a string list

Getting the elements selected of a jlist into a string list

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?
final 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);
}
};

No comments:

Post a Comment