I have created a JComboBox and populated its content from database using DefaultComboBoxModel.
Here is the code:
DefaultComboBoxModel model = new DefaultComboBoxModel();
PreparedStatement statement = con.prepareStatement("SELECT _fid, fruit_name FROM fruits;");
ResultSet result = statement.executeQuery();
while (result.next()) {
model.addElement(result.getString(2));
}
comboBox = new JComboBox(model);
How can I also set the index of the JComboBox with the value of _fid?
I’m fairly new to Java & MySQL and right now I don’t have a working idea.
not true, my class
Itemworks as I expected, in your case required for better help sooner post anSSCCE, otherwise everything here are shots to the dark, for example, you can to modify and applyItemRenderertoo,