如果创建了JPanel,然后添加了一些带有这些规则的JComponents
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
然后如果我想从JDialog中正确删除这个JPanel(删除所有参考文件并将其丢弃到GC)我必须
1/1。必须从JPanel中删除JComponents,然后从JDialog中删除JPanel
2 /只是从JDialog直接删除JPanel
答案 0 :(得分:2)
只需删除面板并且所有侦听器都应该足够,只要您不从其他对象引用任何子组件。