Link to home
Start Free TrialLog in
Avatar of cathalmchale
cathalmchale

asked on

Remove a once-off listener

I have the following:

private boolean firstTime = true;

    // only for initial visuals and selections
    this.addComponentListener(new ComponentListener()
    {
      public void componentResized(ComponentEvent e)
      {
      }
      public void componentMoved(ComponentEvent e)
      {
      }
      public void componentHidden(ComponentEvent e)
      {
      }

      public void componentShown(ComponentEvent e)
      {
        if (firstTime)
        {
          //tree.clearSelection();
          firstTime = false;
        }
      }
    });

once the action has been performed once i want to remove the action - but of course i cant do     this.removeActionLi...  from inside the listener itself!!

Regards,
Cathal.
Avatar of zzynx
zzynx
Flag of Belgium image

     public void componentShown(ComponentEvent e) {
          // Do whatever needed
          Component c = e.getSource();
          c.removeComponentListener(this);
      }
in the above replace
     Component c = e.getSource();
by
     Component c = e.getComponent();
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cathalmchale
cathalmchale

ASKER

that easy ;-)
;°) Life can be easy