Dynamically change JComboBox

Suman.hassan95 picture Suman.hassan95 · Jan 6, 2011 · Viewed 47.2k times · Source

I am fetching the data values from the database successfully. I have also stored them into a String[] array. I need to load the String array as the items of the JComboBox in response to key actionperformed. How can I reload the items of the JComboBox whenever a key is pressed as the fetched values depend on the key pressed. Rather simply, I need to dynamically refresh the JComboBox items.

Answer

camickr picture camickr · Jan 6, 2011
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>( yourStringArray );
comboBox.setModel( model );