Search results
I need to remove all items from the combo box. int itemCount = combo.getItemCount(); for(int i = 0; i < itemCount; i++){ combo.removeItemAt(0); } This code will remove all items except the last one. It gives a NullPointerException. How to fix that?
22 kwi 2015 · Since you have a String array and a JComboBox that have the same items in the same order, you can use the JComboBox.getSelectedIndex() to retrieve the index location of the selected item and remove from the JComboBox and you're array.
Remove one or more items from the combo box's menu. These methods require that the combo box's data model be an instance of MutableComboBoxModel . int getItemCount()
public class JComboBox<E>. extends JComponent. implements ItemSelectable, ListDataListener, ActionListener, Accessible. A component that combines a button or editable field and a drop-down list. The user can select a value from the drop-down list, which appears at the user's request.
23 maj 2023 · This example demonstrate how to add an items into a specific position in the combo box list or at the end of the list using the insertItemAt(Object o, int index) and addItem(Object o) method. In the code we also learn how to remove one or all items from the list using removeItemAt(int index) method and removeAllItems() method of JComboBox.
1 cze 2022 · setMaximumRowCount (int count): sets the maximum number of rows the JComboBox displays. setEnabled (boolean b): enables the combo box so that items can be selected. removeItem (Object anObject) : removes an item from the item list. removeAllItems (): removes all items from the item list.
6 lip 2019 · On clicking the Remove button, the currently selected item will be removed from the combo box. You can download full source code as well as executable JAR file of this program under the attachments section.