Search code examples
javajcomboboxnetbeans-8

Java netbeans How to pass value to jComboBox


How to pass value from one class to jcombobox in another class

Public void getItem (){
try {
         dBconnection...
              while(rs.next){
                  String customers = rs.getString (1);
this.jcombobox1.addItem (customers);
}

}

}

From this method to jcombobox in another class. The error is in jcombobox?


Solution

  • Since you are already having B's class object in A lets say ex Bclassobj.

    Public void getItem (){
    try {
           while(rs.next){
             this.jcombobox1.addItem (rs.getString (1));
             Bclassobj.Bclassjcombobox.addItem (rs.getString (1));
         }
    
        }
       }