Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jcombo box

 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All.

I am fetching all data into combobox. Like
1 = Pepsi
2 = Marinda
3 = CocaCola
4 = Sprite
5 = 7Up

I want that user can only be enable to select "Pepsi and Sprite" the rest of the data must appear into combobox but selection of "Marinda,CocaCola and 7Up" would not be from user.

Can anyone help me out.
 
Vijay Vaddem
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...what i understand is...... u want to list all the items in
combobox BUT do not let the user to select the 3 items. right?

Im not sure if there is any such method to do it.... however,

how abt checking for these values in actionperformed method
and if matched, do nothing??
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pls take a look at JComboBox and ItemSelectable API. That will help you.

--
./pope
[the_mindstorm]
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one send me an example with code.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have ever been in Desktop Application Development using Swing before. I have never seen such feature in JComboBox... I think the most feasible way to fulfil this requirement is to listen for the items that the user tries to choose and react according to his/her choice... But if there is a direct way to implement, it would be better...

Hints as per my suggestion:
-add an ItemListener
-implement itemStateChanged(ItemEvent e)
-check by the items' indices

Hope it helps...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic