Search code examples
javaarrayseclipsecheckboxnumberpicker

Making array of checkbox and numberpicker using java in eclipse


I am trying to make an array of checkboxes using java in Eclipse. I tried this code from someone, but it didn't work. It said: "The constructor CheckBox (string) is undefined" (for the fourth line). What am I supossed to do?

List<CheckBox> checkboxes = new ArrayList<CheckBox>(); String labels[] = {"A", "B", "C", "D", "E", "F"}; for (int i = 0; i < labels.length; i++) { CheckBox checkbox = new CheckBox(labels[i]); checkboxes.add(checkbox); //for further use you add it to the list }

I'm also looking for ways to create array of numberpicker using java in Eclipse, but I still haven't found the way. Can anybody help me? Thank you.


Solution

  • Change you code as suggested by the answer of Suspended. I am providing you with the details:

    List<JCheckBox> checkboxes = new ArrayList<JCheckBox>(); 
    //changed CheckBox to JCheckBox above
    String labels[] = {"A", "B", "C", "D", "E", "F"}; 
    for (int i = 0; i < labels.length; i++) { 
       JCheckBox checkbox = new JCheckBox(labels[i]); 
       //Declared and initialised JCheckBox instead of CheckBox
       checkboxes.add(checkbox); 
       //for further use you add it to the list 
    }
    

    also remember to import javax.swing.JCheckBox;