How to removeAllItems from JComboBox.
It's pretty easy to removeItems from JComboBox once you have added them using JComboBox:addItems methods.
Removing all JComboBox Items
[
import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JComboBox; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JOptionPane; import javax.swing.UIManager; public class JComboBoxRemoveItems extends JFrame implements ActionListener{ public JButton b; public JComboBox box; public JComboBoxRemoveItems() { super("Remove JComboBox Items"); String names []={"Eric","Mutua","James","Bill","Obama"}; try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch(Exception e){} box=new JComboBox(names); box.setBounds(50,50,150,30); add(box); b=new JButton("Remove"); b.setBounds(50, 100, 150, 30); add(b); b.addActionListener(this); setSize(400,400); setLayout(null); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent event) { box.removeAllItems(); JOptionPane.showMessageDialog(this,"All items removed ", "Removing Item from JcomboBox",JOptionPane.INFORMATION_MESSAGE); } public static void main(String args[]) { new JComboBoxRemoveItems(); } }
]