1

I am using a Bonded JComboBox. What I want to know is how do I check if that JComboBox has any items in it or not.

Thank you.

1
  • That's a typo. I just meant plain JComboBox.
    – Rabin
    Commented Nov 14, 2010 at 9:05

1 Answer 1

3

To test if the JComboxBox reference is null, you can compare it with null using the == operator. To test if the combo-box contains any items, you can use the instance method getItemCount, which returns the number of items it contains.

JComboxBox box = ...
boolean boxIsNull = (box == null); // answers the title of the question
boolean boxHasItems = (box.getItemCount() > 0);
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.