if c开发者_如何学运维reated a JPanel and then added some JComponents with these rules
public class MyPanel extends JPanel {
myButton = new MyButton()
myButton.addXxxListener(...)
myButton ....
add(myButton)
}
public class MyButton extends JButton {
//some constructors for parametrize JButton Object
//build only JButton Object value or listener(s) are added in parent
}
//and on runtime are all values added by using constructor or getter/setter
then if I want to remove correctly this JPanel(s) from JDialog (remove all referencies and dispose that to the GC) I must
1/ at 1st. have to remove JComponents from JPanel, thenafter JPanel from JDialog
2/ just directly remove JPanel from JDialog
just removing the panel and all listeners should suffice, as long you don't reference any of its subcomponents from other objects.
精彩评论