【问题标题】:Find and remove a JXTaskpane from a JXTaskPaneContainer从 JXTaskPaneContainer 中查找并删除 JXTaskpane
【发布时间】: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


【解决方案1】:

有很多方法可以实现这一点,可能最简单的方法是将Section 的引用传递给DeleteSectionAction 侦听器

public class DeleteSectionAction implements ActionListener{
    private Section section;
    public DeleteSectionAction(Section section) {
        this.section = section;
    }

    public void actionPerformed(ActionEvent evt) {
        // Personally, I'd have a "removeSection" method in
        // the container that would also remove the
        // section from the array list...
        sectionContainer.remove(section); 
    }

 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-24
    • 2018-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多