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() Get the number of items in the combo box's menu. void setModel(ComboBoxModel) ComboBoxModel getModel() Set or get the data model that provides the items in the combo box's menu.
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.
JComboBox. import javax.swing.JComboBox; public class Main {. public static void main(String[] argv) throws Exception {. String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.removeAllItems(); } }
Java Code Examples for javax.swing.JComboBox # removeAllItems() The following examples show how to use javax.swing.JComboBox #removeAllItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.