I am adding dynamically subPanel
to jPanel1
(with jTextField
and jButton
). Some of part code was borrowed from there.
I am trying to get text from components of jPanel1
, but cannot succeed.
EDITED:
This is a subPanel that contains jTextField
, +Button
and -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);
Here is code of AddButton:
jPanel1.add(new subPanel());
pack();
The code that I am trying to get text from jTextField
doesn't work:
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);
}
Your response will be greatly appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…