JComboBox model doesn't allow to add or remove

R

Rotariu Mihai

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();
}
}
}
}
 
R

Rotariu Mihai

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top