我的想法是点击“添加”按钮,然后将一个按钮添加到JPanel中,我调用了repaint()方法,但是没反应。可是我将窗口托大或托小,就能显示出来了。能帮我修改下吗,谢谢您了!!!import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class RepaintTest extends JFrame implements ActionListener{
private JPanel jpanel = new JPanel();
private JButton jbAdd = new JButton("添加");
private JButton jb = new JButton("按钮");
public static void main(String[] args) {
new RepaintTest();
}


public RepaintTest() {
jbAdd.setPreferredSize(new Dimension(60, 30));
jpanel.setPreferredSize(new Dimension(180,200));
jbAdd.addActionListener(this);

this.setLayout(new FlowLayout());
this.add(jbAdd);
this.add(jpanel);
this.setBounds(400, 150, 200, 300);
this.setVisible(true);
//this.setResizable(false);
}
public void actionPerformed(ActionEvent e) { jpanel.add(jb);
repaint();

}
}