JComboBox model doesn't allow to add or remove

Discussion in 'Java' started by Rotariu Mihai, Nov 21, 2012.

  1. public void keyPressed(KeyEvent e) {

    String ip = (String) jComboBox1.getEditor().getItem();
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_ENTER) {

    if (ip == null || ip.trim().isEmpty()) {
    jComboBox1.setSelectedItem("Please insert a keyword!");
    } else {

    if (jRadioButton1.isSelected()) {

    model.removeAllElements();
    }
    }
    }
    }
    Rotariu Mihai, Nov 21, 2012
    #1
    1. Advertising

  2. DefaultComboBoxModel model = new DefaultComboBoxModel();
    jComboBox1 = new javax.swing.JComboBox(model);
    jComboBox1.setModel(model);

    This is how I set the model for the jComboBox. Can you please take a look and let me know why is not working?

    Thanks
    Rotariu Mihai, Nov 21, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KLD
    Replies:
    3
    Views:
    1,173
    Tony Morris
    Feb 15, 2004
  2. Jeff
    Replies:
    2
    Views:
    924
    clintonG
    Sep 19, 2006
  3. @CL
    Replies:
    1
    Views:
    466
  4. Ryan Taylor
    Replies:
    1
    Views:
    668
    Ryan Taylor
    Sep 9, 2004
  5. Rotariu Mihai
    Replies:
    5
    Views:
    356
    Knute Johnson
    Nov 22, 2012
Loading...

Share This Page