How to get items from JComboBox component?

From the JComboBox it is easy to get items from the JComboBox component.
First of all we need to get item count using getItemCount() method then we can iterate over the items of ComboBox and call the getItemAt() method to get items at respective index.


String[] cmbMenu = {"menu1", "menu2", "menu3", "menu4"};
JComboBox cmbBoxMenu = new JComboBox( cmbMenu );

//Calling getItemCount to get number of items from JComboBox component.
int numOfMenus = cmbBoxMenu.getItemCount();

//Calling getItemAt method to get menu.

for ( int i = 0; i < numOfMenus; i++) {
String menu = (String)cmbBoxMenu.getItemAt(i);
}
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment