• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

append getSelectedValues?

 
Patty Kingsmill
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Patty
 
Chad Clites
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that gave me a start to search for a solution and I found it:

getMaxSelectionIndex()

Patty
 
Brian Cole
Author
Ranch Hand
Posts: 899
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic