I have 25 jButtons and i want to change their texts from a loop. Here is my code for 1 button..
void changeText(){
jButton1.setText(jButton1.getText().toUpperCase());
}
I want to do the same for all other buttons without writing a method for each.
Is it possible to use something like this?
void changeText(){
for(int i=0;i<25;i++){
String x = "jButton"+i;
x.setText(x.getText().toUpperCase());
}
}
Surely this wont work. Please suggest me a method.
You can do this by adding the buttons to a collection.
Something like this:
Later you can iterate over the list of buttons: