setName
is used for internal identification of the component. Imagin you've been give a list of components, all you know is you need to find the one with some unique identifier, that identifier is supplied via the name
property. It has no effect on the output of the component.
You need to use the setText
method to change what is displayed on the screen.
The next problem you'll have is setText
is a replacement method. That is, it will replace what ever was previously applied with the new value. What might need to do is build a temporary String
of the values you want to display and then apply that value to the label, for example...
StringBuilder sb = new StringBuilder(64);
for (i = 0; i < indices.length; i++) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(countries[indices[i]]);
}
countryLabel.setText(sb.toString());