• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to restrict user from selecting a particular value in JLISt

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JList bu the name organisationList and it contails many values
like ALL , US , UK, INDIA



The list allows multiple selection
I have a requirement in which the user should not be able to select ALL,
if he/she has already selected any other item

Can any body help me tackle this.

Regards,

Ivin.Jacob
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ivin jacob:


The list allows multiple selection
I have a requirement in which the user should not be able to select ALL,
if he/she has already selected any other item



Take a look at the API documentation. The JList has a setSelectionMode(int mode) method which will help you achieve the desired control.
 
ivin jacob
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm that doesnt help
 
ivin jacob
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that doesnt help
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maneesh Godbole:
The JList has a setSelectionMode(int mode) method which will help you achieve the desired control.



Perhaps he means setSelectionModel(ListSelectionModel selectionModel)? Unlike setSelectionMode(), that will indeed give you the control you need.

You will probably want to extend DefaultListSelectionModel, override some methods [setSelectionInterval(), addSelectionInterval(), possibly others] and set your custom selection model onto your JList.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian Cole:


Perhaps he means setSelectionModel(ListSelectionModel selectionModel)? Unlike setSelectionMode(), that will indeed give you the control you need.



No. I did mean setSelectionMode. and not setSelectionModel.

I have a requirement in which the user should not be able to select ALL,
if he/she has already selected any other item



If the mode is set to SINGLE_SELECTION, the user will not be able to select all. Is this the desired control or have I perhaps misunderstood the requirement?
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You misunderstood.

The selection should be either ALL, or any combination of INDIA, US and UK. So:
- if ALL is selected that should be the only selection
- if INDIA, US or UK is selected, any other can be selected except ALL

So the second case does allow for multiple selection.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
You misunderstood.



Oh I see it. I took ALL for all elements in the list. Doh!
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
The selection should be either ALL, or any combination of INDIA, US and UK. So:
- if ALL is selected that should be the only selection
- if INDIA, US or UK is selected, any other can be selected except ALL

So the second case does allow for multiple selection.



Here's a quick-and-dirty selection model that almost does this, but differs when the user tries to add ALL to a non-empty selection. Instead of preventing ALL from being selected, this code selects the ALL but deselects everything else.



As you can see, a custom selection model can pretty much control everything, which is why I thought perhaps Mr. Godbole intended to recommend setSelectionModel() instead of setSelectionMode().
reply
    Bookmark Topic Watch Topic
  • New Topic