Skip to content

Dynamically change JComboBox

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.


DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>( yourStringArray );
comboBox.setModel( model );