Dynamic JFrame in java
I have a project and I need to know how to adding a component in a JFrame when pressing a JButton. I have added a panel into panel by this code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 开发者_StackOverflow
colorPanel color0=new colorPanel();
color0.setBounds(5,150+nb,300,120);
color0.setLayout(new FlowLayout());
this.getContentPane().add(color0);
this.validate();
System.out.println("add couleur:"+nb);
nb+=50;
}
It works but the problem is that the component is deleted when I maximize or minimize the JFrame. Thanks.
When you resize your Jframe, a repaint() & paint() methods are called which probably erases your component.
精彩评论