Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JComboBox problem, pse help!

Reply
Thread Tools

JComboBox problem, pse help!

 
 
Tobi Krausl
Guest
Posts: n/a
 
      11-27-2003
Hi,

I've a question concerning JComboBox:

In my program a use a JComboBox which is initialized with a list of
values at program startup. During runtime, this JComboBox is editable
so that a user can enter his own values.

I want to do following: After the user entered a valued in the
textfield of the JComboBox and a button is pressed, there should be
checked whether the JComoBox already contains the entered value. If
so, fine! If not, JComboBox.addItem(...entered value...).

How can I check whether a JComboBox or its related model already
contains a certain value??

Obviously there's no method like JComboBox.contains(Object o) or
JComboBox.getModel().contains(Object o)?!

Thank you,
Tobi
 
Reply With Quote
 
 
 
 
ak
Guest
Posts: n/a
 
      11-27-2003

"Tobi Krausl" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) m...
> Hi,
>
> I've a question concerning JComboBox:
>
> In my program a use a JComboBox which is initialized with a list of
> values at program startup. During runtime, this JComboBox is editable
> so that a user can enter his own values.
>
> I want to do following: After the user entered a valued in the
> textfield of the JComboBox and a button is pressed, there should be
> checked whether the JComoBox already contains the entered value. If
> so, fine! If not, JComboBox.addItem(...entered value...).
>
> How can I check whether a JComboBox or its related model already
> contains a certain value??
>
> Obviously there's no method like JComboBox.contains(Object o) or
> JComboBox.getModel().contains(Object o)?!


see javax.swing.DefaultComboBoxModel



 
Reply With Quote
 
 
 
 
Tobi Krausl
Guest
Posts: n/a
 
      11-28-2003
> see javax.swing.DefaultComboBoxModel

Fine, but javax.swing.DefaultComboBoxModel doesn't contain an obvious
solution for my problem. There's no method like "boolean
contains(Object o)".
There must be an easier solution than getting the size of the
DefaultComboBoxModel and iterate over all items?!!

Tobi
 
Reply With Quote
 
Adam
Guest
Posts: n/a
 
      11-28-2003
> Fine, but javax.swing.DefaultComboBoxModel doesn't contain an obvious
> solution for my problem. There's no method like "boolean
> contains(Object o)".
> There must be an easier solution than getting the size of the
> DefaultComboBoxModel and iterate over all items?!!


BTW, if 'boolean contains(Object o)' existed
it would probably iterate over all items to find the match.


Adam


 
Reply With Quote
 
Tobi Krausl
Guest
Posts: n/a
 
      11-28-2003
> BTW, if 'boolean contains(Object o)' existed
> it would probably iterate over all items to find the match.


That's exactly what I would need. However, it seems that this method
doesn't exist anymore. I use SDK1.4.2
 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      11-28-2003
we told you really everything what you need to write following:

public boolean contains(DefaultComboboxModel model, Object o) {
int size = model.getSize();
for(int i = 0; i < size; i++) {
Object obj = model.elementAt(i);
if(obj.equals(o)) {
return true;
}
}
return false;
}

--

____________

http://reader.imagero.com the best java image reader.

"Tobi Krausl" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) m...
> > BTW, if 'boolean contains(Object o)' existed
> > it would probably iterate over all items to find the match.

>
> That's exactly what I would need. However, it seems that this method
> doesn't exist anymore. I use SDK1.4.2



 
Reply With Quote
 
Tobi Krausl
Guest
Posts: n/a
 
      12-01-2003
> we told you really everything what you need to write following:
>
> public boolean contains(DefaultComboboxModel model, Object o) {
> int size = model.getSize();
> for(int i = 0; i < size; i++) {
> Object obj = model.elementAt(i);
> if(obj.equals(o)) {
> return true;
> }
> }
> return false;
> }


Thank you very much!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Last Day: SUPERMAN DVD. PSE GLENGARRY GLEN ROSS LD, DTS NIGHTMARE XMAS LD J Rusnak DVD Video 0 10-02-2006 05:02 AM
PSE : Python Servlet Engine configuration salvatore Python 0 01-23-2005 03:39 PM
PSE 70-296 Olivier MCSE 29 12-23-2004 02:41 AM
PSE 3 engine Conrad Weiler Digital Photography 0 09-23-2004 01:08 PM
Pse explain "3.1m effective pixels and 6.0m redorded pixels" notreallyme Digital Photography 14 12-28-2003 03:41 PM



Advertisments