我正在编写一个JPanel包含JLabels 和JTextFields 的程序。我想在单击按钮时添加新的JLabels 和s 行。JTextField我试过这段代码,但它不起作用。
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JTextField txt= new JTextField();
jPanel2.add(txt);
jPanel2.validate();
jPanel2.repaint();
}