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.
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);