我正在編寫一個選項的pannel,爲了能夠在開發應用程序時更快地添加更多選項,我決定將所有輸入的組件都放在一個Frame中,我需要從配置中加載它們的值並設置相應的文本,但似乎無法從字段中獲取組件的文本。 我收到了:
線程「AWT-EventQueue-0」中的異常java.lang.RuntimeException:不可編譯的源代碼 - 錯誤的sym類型:java.awt.Component.setText
Nombre:server Clase:class javax。 swing.JTextFieldJava,Swing,獲取和更改所有輸入字段
private void loadConfigs() {
List<Component> compList = getAllComponents(this);
System.out.println("Tamaño "+compList.size());
for(int i=0; i<compList.size();i++) {
if(compList.get(i).getName() != null) {
System.out.println("Nombre: "+compList.get(i).getName() +" Clase:"+ compList.get(i).getClass().toString());
if(compList.get(i).getClass().toString().matches("class javax.swing.JTextField")) {
System.out.println("Machea load " +compList.get(i).getName() + compList.get(i).toString());
compList.get(i).setText(rootFrame.config.get(compList.get(i).getName()));
}
else if(compList.get(i).getClass().toString().matches("class javax.swing.JCheckBox")) {
if (rootFrame.config.get(compList.get(i).getName()) == null) {
compList.get(i).setSelected(false);
}
else {
compList.get(i).setSelected(true);
}
}
}
}
}
public static List<Component> getAllComponents(final Container c) {
Component[] comps = c.getComponents();
List<Component> compList = new ArrayList<Component>();
for (Component comp : comps) {
compList.add(comp);
if (comp instanceof Container) {
compList.addAll(getAllComponents((Container) comp));
}
}
return compList;
}
*「並且能夠在開發應用程序時更快地添加更多選項,我決定將所有輸入的組件都放在一個Frame中*」這可能會以'在大桶中'結束,它會有對我來說同樣重要。框架與快速添加內容有什麼關係? –