I have a array
string with the names of some controls Label
and I want to reference them by that name. Or what is the same, I want to pass a String
to a control Label
. For example, in VBA it would be like this:
for i=0 to 10
formulario.Controls(miarray(i)).setcaption = ""
next i
But how do I do it in Java?
To achieve this purpose, it is necessary to obtain the Component that your Container has . Since you only want to manipulate them,
JLabel
you would have to verify that the Component is of typeJLabel
, this is done through the operatorinstanceof
, if this is true, it would be necessary to validate that the name of the component is within yourArray
of Names.