我有一个模型视图控制器应用程序。该视图包含一个带有多个 JXTaskPane 的 JXTaskContainer。JXTaskPane 有一个删除按钮,可以将其从容器中删除。
假设所有通过单击按钮自动添加的 JXTaskpanes,我如何找到正确的 JXTaskPane,然后将其从容器中删除?
`enter code here`class Holder extends JFrame {
Arraylist <Section> sectionList = new ArrayList<Section>();
JPanel holderPanel = new JPanel;
JXTaskPaneContainer sectionContainer = new JXTaskPaneContainer();
this.add(holderPanel);
// here goes other stuff
class AddSectionAction implements ActionListener{
//actionPerformed
Section section = new Section();
section.addActionListener(new DeleteSectionAction);
sectionList.add(section);
sectionContainer.add(section);
holderPanel.add(sectionContainer);
holderPanel.revalidate();
holderPanel.repain();
}
class DeleteSectionAction implements ActionListener{
//actionPerformed
sectionContainer.remove(THE SECTION I WANT TO REMOVE );
}
}
public class Section extends JXTaskPane {
JTextArea textArea;
JButton deleteMe;
//other stuff here
public JButton getDeleteMe{
return deleteMe;
}
}