I have a project on netbeans that uses Java Swing for the interface. I have some data in MYSQL that would like to show them as soon as the window is created.
Finally, how can I dynamically place items in a JComboBox in Java?
I have a project on netbeans that uses Java Swing for the interface. I have some data in MYSQL that would like to show them as soon as the window is created.
Finally, how can I dynamically place items in a JComboBox in Java?
As you have no more details, I'll give you the most generic answer possible.
Just use the method addItem
combobox.addItem("Item 1");
combobox.addItem("Item 2");
combobox.addItem("Item 3");
1) First you have to make the connection this can be done in Pure JDBC or JPA
2) You create a DAO based on one of the example
3) In Your JFrame class you will do the following
public class SeuFrame(){
public SeuFrame(){
carregarCombo();
}
public void carregarCombo(){
SeuDAO dao = new SeuDAO();
List<SuaClasse> list = dao.lista();
for(SuaClasse item: list){
seuCombobox.addItem(item);
}
}
}