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.
A JComboBox is a component that displays a drop-down list and gives users options that we can select one and only one item at a time whereas a JList shows multiple items (rows) to the user and also gives an option to let the user select multiple items.
u can make ur jcombobox uneditable by calling its setEnabled(false). A JComboBox is unEditable by default. You can make it editable with the setEditable(boolean) command. If you are talking about enabled or disabled you can set that by the setEnabled(boolean) method.
JComboBox is a part of Java Swing package. JComboBox inherits JComponent class . JComboBox shows a popup menu that shows a list and the user can select a option from that specified list . JComboBox can be editable or read- only depending on the choice of the programmer .
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>( yourStringArray ); comboBox.setModel( model );
You have a couple of options. You can use removeAllItems()
(or one of the other remove methods) and addItem(Object anObject)
to manipulate the selectable objects. Or you could implement a ComboBoxModel
and allow it to serve up data from your array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With