Reputation: 1658
javax.swing.JComboBox class does not support the setText method. Is there a way on how can I set the text of an editable combo box? Like something that I can call jcombobox1.setText("Text has changed!");
Upvotes: 5
Views: 36885
Reputation: 51536
You can set the selectedItem to whatever value you want:
comboBox.setSelectedItem("text has changed");
Note that the selectedItem is explicitly documented to allow elements which are not part of the model.
Upvotes: 9
Reputation: 103155
Once you set the JComboBox to editable you can do this:
String item = box.getEditor().getItem().toString();
To get the String the user typed or selected. And
box.getEditor().setItem("Text Has Changed");
to set your own text.
Upvotes: 16