I have at problem with dynamic checkboxes. I want a combobox to show beside the checbox/checkboxes when one or more is selected. But I only get one combobox, which moves around whenever I select a new checkbox. So can anybody helpe me by telling me whats wrong and how I get more than one combobox?
for(int i = 0; i < names.length; i++) {
// ParameterField
JTextField fieldParam = new JTextField();
fieldParam.setText(names[i]);
fieldParam.setEditable(false);
addElement(contentPanel, fieldParam, 25, yPos, 100, 20);
// ValueField
JTextField fieldValue = new JTextField();
fieldValue.setText("" + values[i]);
fieldValue.setEditable(false);
addElement(contentPanel, fieldValue, 160, yPos, 100, 20);
//RadioButtonField
final JCheckBox checkboxes = new JCheckBox();
checkboxes.setActionCommand(names[i]);
checkboxes.addActionListener(this);
addElement(contentPanel, checkboxes, 325, yPos, 100, 20);
final int checkBoxIndex = i;
checkboxes.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae2) {
if (checkboxes.isSelected()) {
comboProcent.setEnabled(true);
comboProcent.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"2%", "5%", "10%"}));
addElement(contentPanel, comboProcent, 435, 50 + checkBoxIndex * 25, 80, 20);
setVisible(true);
}
if (!checkboxes.isSelected()) {
contentPanel.remove(comboProcent);
}
System.out.println("checkbox is: " + checkBoxIndex);
}
});
yPos = yPos + 25;
}