【发布时间】:2012-10-14 15:28:03
【问题描述】:
我有一个模型视图控制器应用程序。该视图包含一个带有多个 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;
}
}
【问题讨论】:
-
您可能会像删除
JComponent一样删除JXTaskContainer,因此请先尝试。为了尽快获得更好的帮助,请发布您的最佳尝试SSCCE。 -
我有一个数组列表,它保存面板并在单击按钮时自动将新面板添加到 JFrame 中。此外,每次单击按钮时,我都会将面板添加到数组列表中。现在我想要一个删除按钮来帮助我删除面板。请问怎么办?
-
“请问如何处理?”请在您发布 SSCCE 时告诉我。
-
好的,我试着给你一段代码:
标签: java swing swingx jxtaskpane