0

I have a model view controller application. The view contains a JXTaskContainer with several JXTaskPane. The JXTaskPane has a delete button that will remove it from the container.

How can I find the right JXTaskPane and then delete it from the container assuming the JXTaskpanes where all added automatically by clicking a button?

`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;
   }
 }
Pukka
  • 11
  • 3
  • 2
    You'd probably remove a `JXTaskContainer` the same way you would do it with a `JComponent`, so try that first. For better help sooner, post an [SSCCE](http://sscce.org/) of your best attempt. – Andrew Thompson Oct 14 '12 at 15:32
  • I have an array list that saves panels and automatically adds a new panel into a JFrame on the click of a button. Also i add the panels to the array list every time the button is clicked. Now i want a delete button to help me remove the panel. Please how do go about it? – Pukka Oct 14 '12 at 17:46
  • *"Please how do go about it?"* Please tell me when you post an SSCCE. – Andrew Thompson Oct 14 '12 at 18:05
  • Ok, I'll try to provide you a piece of code: – Pukka Oct 14 '12 at 18:18

1 Answers1

0

There are a number of ways to achieve this, probably the easiest is to pass a reference of the Section to the DeleteSectionAction listener

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); 
    }

 }
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366