My JTextField Name is
Query0, Query1, Query2, Query3, Query4
I am trying to change the name with the loop. Is it possible to do this in java
String[] StoreValueFromTable = new String[5];
String[] ColumName = new String[5];
JTextField[] Query = new JTextField[5];
for(int Count=0;Count<5;Count++){
StoreValueFromTable[Count] = "QueryTechnica"+Count;
ColumName[Count] = "QT"+(Count+1);
Query[Count] = new JTextField();
StoreValueFromTable[Count] = rs.getString(ColumName[Count]);
Query<Count>.setText(StoreValueFromTable[Count]);
Query<Count>.setEditable(false);
//Text Field Name is Query0, Query1, Query2, Query3, Query4
}
I am not aware that you can change the name of an actual variable, that being said, you could use a Map<String, JTextField>
to accomplish your goal.
In this case, the key would be the name you want to assign to the JTextField. To rename, simply remove the old key and add the new one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.