• Post Reply Bookmark Topic Watch Topic
  • New Topic

recursive Method for ComboBox  RSS feed

 
David Hittel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i have following Problem. On one Panel i have eight JComboBox's named JComboBox(1-8).

Now i have following Method to fill the ComboBox model

public void updateJComboBox() {

DefaultComboBoxModel model = (DefaultComboBoxModel)jComboBox1.getModel();
Rohstoff Ro =null;

Object[] tabelle = all_Rohstoff.getAll();

for(int i=0;i< tabelle.length;i++) {
Ro = (Rohstoff)tabelle[i];
model.addElement(Ro.getName());

}
}

This is working fine, but i don't want to repeat the method 8 times. Is it possbile to fill all 8 Boxes trough one method call.

This line has to be different

DefaultComboBoxModel model = (DefaultComboBoxModel)jComboBox1.getModel();


Thanks alot

David
 
Campbell Ritchie
Marshal
Posts: 56586
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you set up an Array or ArrayList containing the JComoboxes and iterate through the array or List?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the method signature to

public void updateJComboBox(JComboBox combobox) {

then you can call the method for different comboboxes.
 
David Hittel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey

Some solutions are so easy that i dont tought about it.

Thanks a lot for your help

David
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!