jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes Jcombo box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jcombo box" Watch "Jcombo box" New topic

Jcombo box

Anand Karia
Ranch Hand

Joined: Sep 25, 2004
Posts: 156

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.

Love is GOD and GOD is Love.
Anand Karia
IT Concretor.......
M/s. Anand Karia Concreting IT
Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243
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

Joined: Jul 12, 2004
Posts: 995
Pls take a look at JComboBox and ItemSelectable API. That will help you.


blog - InfoQ.com
Anand Karia
Ranch Hand

Joined: Sep 25, 2004
Posts: 156

Can any one send me an example with code.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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...

Co-author of SCMAD Exam Guide, Author of JMADPlus
I agree. Here's the link: http://aspose.com/file-tools
subject: Jcombo box
It's not a secret anymore!