I did not find any solution to my problem, so here it is.
I would like to access my JLabels. All of my labels have numbers behind them, and I would like to change these numbers and access my labels that way.
Example:
JLabel1.setText("how");
JLabel2.setText("can");
JLabel3.setText("I");
JLabel4.setText("access");
JLabel5.setText("these");
JLabel6.setText("better");
I would like to access them in a loop by changing the number at the end of the variable name, and assign values to them that way, as I will be using a lot of labels, and I would like to change the content of the labels many times.
Something like this with the above example:
String[] texts = {"how", "can", "I", "access", "these", "better"};
// this is the part I do not know, if it can be done or not.
for (int i = 0; i < texts.length; i++) {
JLabel+(i+1).setText(texts[i]);
}
This code does not work, but I am here to seek help and find a solution for this problem. Any solution you might have, I would love to hear it, and hopefully I will understand it. I am only a Student, but I'll try my best.
I am using Netbeans IDE 8.1, and using it in GUI builder(This might not matter, but just in case).