0

I try to obtain name of List of JCheckBox but appear a string null. This is my code;

JCheckBox mesi [] = {gennaioCheck, febbraioCheck, marzoCheck, aprileCheck, maggioCheck, giugnoCheck,
    luglioCheck, agostoCheck, settembreCheck, ottobreCheck, novembreCheck, dicembreCheck};

    for (JCheckBox m : mesi){
        if (m.isSelected()){
            System.out.println(m.getName());

        }
martinez314
  • 12,162
  • 5
  • 36
  • 63

1 Answers1

3

You probably mean to use getText().

System.out.println(m.getText());
martinez314
  • 12,162
  • 5
  • 36
  • 63
  • Thanks, now it is work. I think that getText() doesn't work with checkBox – Barbara Privitera Jan 11 '16 at 21:52
  • 2
    @BarbaraPrivitera `getText` will return the text which is displayed on the screen, `getName` will return a name which you apply to it (via `setName`), which can be used when the text is dynamic (or to long to keep typing in). An alternative would be to use `set/getActionCommand` – MadProgrammer Jan 11 '16 at 21:58