Removing all Items from a combo box in Java

前端 未结 9 1165
自闭症患者
自闭症患者 2021-02-06 11:04

I need to remove all items from the combo box

    int itemCount = combo.getItemCount();

    for(int i=0;i

        
9条回答
  •  不知归路
    2021-02-06 11:28

    Usually it happens because you have an event associated JComboBox. It is solved if you have control item in the JComboBox to act, for example:

    jComboBoxExample.addActionListener (new ActionListener () {
       public void actionPerformed (ActionEvent e) {
         do_run ();
       }
    });
    
    
    
    public void do_run() {
      int n=jComboBoxPerfilDocumentos.getItemCount(); <--THIS IS THE SOLUTION
      if (n> 0) { 
        String x = jComboBoxPerfilDocumentos.getSelectedItem (). ToString ();
      }
    }
    

提交回复
热议问题