[英]Change JTextField Variable name with loop in Java
My JTextField Name is 我的JTextField名称是
Query0, Query1, Query2, Query3, Query4
Query0,Query1,Query2,Query3,Query4
I am trying to change the name with the loop. 我正在尝试通过循环更改名称。 Is it possible to do this in java
是否可以在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. 我不知道您可以更改实际变量的名称,也就是说,可以使用
Map<String, JTextField>
来实现您的目标。
In this case, the key would be the name you want to assign to the JTextField. 在这种情况下,键将是您要分配给JTextField的名称。 To rename, simply remove the old key and add the new one.
要重命名,只需删除旧密钥并添加新密钥即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.