I don't know if the title is correct, but what I want to do is to write a method that adds for example the rgb of a color to a combobox. Let's assume that we have 3 panels each one with different background color and each panel has its own combo box.
int p1RGB = (Panel1.getBackground()).getRGB();
int p1Red = (p1RGB>>16)&0xFF;
int p1Green = (p1RGB>>8)&0xFF;
int p1Blue = p1RGB&0xFF;
String p1RGBStr = String.valueOf(p1Red) +", "+String.valueOf(p1Green) +", "+ String.valueOf(p1Blue);
String[] c1Items = { hex1, p1RGBStr };
DefaultComboBoxModel model1 = new DefaultComboBoxModel (c1Items);
Combo1.setModel(model1);
Instead writing again this code for each panel can I write this in a way that it loops itself for each panel? I think there is something similar in javascript.