I have a JList
that is populated from database. My idea is , when i click in one item from JList
, that selection is saved on a String
.
final JList list = new JList();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setBounds(24, 107, 256, 407);
getContentPane().add(list);
How I can save in String
, a item selected from JList
? need to do any ActionListener
?
You'll have to implement a
ListSelectionListener
and in the method
valueChanged(...)
you can store the value of the selected String by using
String value = list.getSelectedValue();
or if you have selected more you can use a String array as
String[] values = list.getSelectedValues();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.