I am doing a home work for my class in java, i am using NetBeans. When the frame opened i want that my combo box load data that is exactly to my database column. Exp... On my 7 column on my data base there's a column name that's name Color, and on the list of column there's yellow. I want that my jCombobox load with Yellow and get's all the others color on the model. Here is my code
private void formWindowOpened(java.awt.event.WindowEvent evt) {
txt_id.setText(user);
SQLiteConnection DB = new SQLiteConnection ();
String question = DB.getQuestionUser();
DB.getUtilisateur(user);
cbx_question.addItem(question);
}
It keep on add item on the list of my model but do not show what is on the database column. Hope that you will understand
The easiest way to populate a
JComboBox
is to supply the data when you call the constructor.There are three different constructors you can call (supplying your data structure):
You need to check what return type the database query has and convert it into one of the three previous data structures.
Later, if you wish to use the same
JComboBox
object to display other data (same type as before) you can do so by callingsetModel( ComboBoxModel<E> model )
Source: Oracle documentation page