Domanda

I am not able to get why null is appearing. The checkBox should have a name assigned to it

    imagesToBeImportedCheckBox = new JCheckBox[imagesToBeImported.size()];
    int check_Box_Number=0;
    for(ResourceListObject currentImage : imagesToBeImported){


        imagesToBeImportedCheckBox[check_Box_Number] = new JCheckBox(currentImage.getName());

        System.out.println("Main Debugger On");
        System.out.println(currentImage.getName());
        System.out.println(check_Box_Number);
        System.out.println(imagesToBeImportedCheckBox[check_Box_Number].getName());

        imagesToBeImportedCheckBox[check_Box_Number].setBounds(6, gapping+check_Box_Number*26, 368, 23);

        panel_1.add(imagesToBeImportedCheckBox[check_Box_Number]);
        check_Box_Number++;

            }

and here's the output

Main Debugger On
Migration-image
0
null
Main Debugger On
Imported on: Tuesday, August 20, 2013
1
null
È stato utile?

Soluzione

I think you are confusing the name property for the text property

System.out.println(imagesToBeImportedCheckBox[check_Box_Number].getName());

Should be

System.out.println(imagesToBeImportedCheckBox[check_Box_Number].getText());

The text property is responsible for determining what is actually displayed on the screen.

It is also what is set when you pass a String to JCheckBox's constructor...

... = new JCheckBox(currentImage.getName());

Will set the JCheckBox's text property

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top