| Author |
append getSelectedValues?
|
Patty Kingsmill
Greenhorn
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. Patty
|
 |
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
Greenhorn
Joined: Nov 20, 2005
Posts: 7
|
|
Thanks, that gave me a start to search for a solution and I found it: getMaxSelectionIndex() Patty
|
 |
Brian Cole
Author
Ranch Hand
Joined: Sep 20, 2005
Posts: 852
|
|
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
|
 |
 |
|
|
subject: append getSelectedValues?
|
|
|