This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How we can restrict the no of selections in a JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How we can restrict the no of selections in a JList" Watch "How we can restrict the no of selections in a JList" New topic
Author

How we can restrict the no of selections in a JList

kota murali
Greenhorn

Joined: Jun 26, 2002
Posts: 1
Hi,
How we can restrict to select max. no of items in a JList.
Ex: JList has to restrict that user can select max of 3 selections which is having 50 items.
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
I don't think there is any direct way to do that but you can add a listener to the list
(addListSelectionListener) that's notified each time a change to the selection occurs.In case user selects more than three you can call
clearSelection() to change the selection to empty set.


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

"k murali" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How we can restrict the no of selections in a JList
 
Similar Threads
HashMap problem
append getSelectedValues?
JList Autosearch with Custom Renderer
Selecting List Items on right Click
ListSelectionListener in JTable