Subscribe My channel to get more Updated Videos
/ @techprogrammingideas
How to populate JComboBox using a method that accepts string as combobox name
JComboBox basic tutorial and examples
Method
public void populateComboBox(JComboBox comboBox) {
DefaultComboBoxModel model = new DefaultComboBoxModel();
Connection con = ConnectionManager.getConnection();
try{
Statement stmt = null;
String query = "SELECT id, name FROM states WHERE 1";
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
model.addElement(new ComboItems(rs.getString(2), rs.getString(1)));
}
comboBox.setModel(model);
rs.close();
con.close();
}catch(SQLException e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
******************
ConnectionManager z= new ConnectionManager();
z.populateComboBox(cmbState);
#JComboBox
#javaTutorials
https://techprogrammingideas.blogspot...
PSC Study Materials and Previous Question Papers
http://www.mission2win.in/
Any doubts and help to type comments below