Could someone tell me how to get the selected item of JList
to a String
? It is a single selection JList
.
The JList component is backed by a list model. So the only recommended way to remove an item from the list view is to delete it from the model (and refresh the view). If he's using a DefaultListModel (and in all likelihood he is), then there's no need to refresh the view since this should be done automatically.
Multiple selection list enables the user to select many items from a JList. A SINGLE_INTERVAL_SELECTION list allows selection of a contiguous range of items in the list by clicking the first item, then holding the Shift key while clicking the last item to select in the range.
Try this:
String selected = jList1.getSelectedValue();
If you want the value of the selected item to a string you should try
String a = jList1.getSelectedValue().toString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With