permaculture playing cards
The moose likes Swing / AWT / SWT and the fly likes append getSelectedValues? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "append getSelectedValues?" Watch "append getSelectedValues?" New topic

append getSelectedValues?

Patty Kingsmill

Joined: Nov 20, 2005
Posts: 7
I have the following code:

Users are able to select an item from the catalogItems JList. I would like to be able to count the number of selections made. I was thinking I could use a SINGLE_INTERVAL_SELECTION mode and count the number of times the user hits the "Select" button and use that count to perform a calculation in the "Finish and Save" ActionEvent. But, I want to display each selection listed in custSelections - is it possible to append?

Alternatively, if I allow a MULTIPLE_INTERVAL_SELECTION, how do I count the number of items in the custSelections JList?

Your advice is appreciated.
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
This may only be moderately helpful, bit IIRC, when allowing multiple selections, the selections are saved in an array/collection. Then they can be retrieved with either getSelectedIndices, or getSelectedValues. I did something similar with JFileChooser a long time ago, but the exact code escapes me at the moment.

That's about all I can recall of the process at the moment (and there is more to it). Maybe this will be enough to at least give you a push in the right direction.
Patty Kingsmill

Joined: Nov 20, 2005
Posts: 7
Thanks, that gave me a start to search for a solution and I found it:


Brian Cole
Ranch Hand

Joined: Sep 20, 2005
Posts: 878
getMaxSelectionIndex() doesn't tell you how
many selections there are, just the index of
the highest selected item.

Clites showed you how to get a list of the
selected items and/or indices. If you only
want the count you can do

int numSelected = jlist.getSelectedIndices().length;

bitguru blog
I agree. Here's the link:
subject: append getSelectedValues?
It's not a secret anymore!