Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DefaultComboBoxModel model = new DefaultComboBoxModel( yourStringArray );
- comboBox.setModel( model );
- public class ComboPanel extends JPanel {
- JComboBox jcbo;
- // this is constructor
- public ComboPanel(ArrayList<String> items) {
- jcbo = new JComboBox();
- // getting exiting combo box model
- DefaultComboBoxModel model = (DefaultComboBoxModel) jcbo.getModel();
- // removing old data
- model.removeAllElements();
- for (String item : items) {
- model.addElement(item);
- }
- // setting model with new data
- jcbo.setModel(model);
- // adding combobox to panel
- this.add(jcbo);
- }
- }
- JComboBox op=new JComboBox(new String[] {"d","e","f"});
- op.removeAllItems();
- String[] new_entries=new String[] {"a","b","c"}
- for (String s : new_entries) {
- op.insertItemAt(s, op.getItemCount());
- }
- op.setSelectedIndex(0);
Add Comment
Please, Sign In to add comment