obter texto do jPanel adicionado dinamicamente
Estou adicionando dinamicamentesubPanel
parajPanel1
(comjTextField
ejButton
) Parte do código da peça foi emprestada delá.
Estou tentando obter texto de componentes dejPanel1
, mas não pode ter sucesso.
EDITADO: Este é um subPainel que contémjTextField
, +Button
e-Button
.
private class subPanel extends javax.swing.JPanel {
subPanel me;
public subPanel() {
super();
me = this;
JTextField myLabel = new JTextField(15);
add(myLabel);
JButton myButtonRemove = new JButton("-");
JButton myButtonAdd = new JButton("+");
add(myButtonRemove);
add(myButtonAdd);
Aqui está o código do AddButton:
jPanel1.add(new subPanel());
pack();
ocódigo que estou tentando obter textojTextField
não funciona:
Component[] children = jPanel1.getComponents();
for (int i=0;i<children.length;i++){
if (children[i] instanceof JTextField){
String text = ((JTextField)children[i]).getText();
System.out.println(text);
}
Sua resposta será muito apreciada.