オプションのパネルをコーディングしています。アプリケーションの開発中にオプションをより速く追加できるようにするために、すべての入力のコンポーネントをフレームに入れることにしました。構成からそれらの値をロードし、対応する値を設定する必要があります。テキストですが、フィールドからコンポーネントのテキストを取得できないようです。スレッド「AWT-EventQueue-0」の例外が
発生しますjava.lang.RuntimeException:コンパイルできないソースコード-誤ったsymタイプ:java.awt.Component.setText
Nombre:サーバーClase:class javax.swing.JTextField
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;
}