How to add an ActionListener to the ImageJ menu

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add an ActionListener to the ImageJ menu

Piotr Wendykier
Hello,

I'm trying to add an ActionListener to the ImageJ menu, but my code
does not work:

MenuBar menuBar = IJ.getInstance().getMenuBar();
Menu menu = menuBar.getMenu(0);
menu.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        //TODO
    }
});

It looks like the only ActionListener that is added to the menu is ij.ImageJ.
In my plugin I want to respond to ImageJ menu events (in particular, I
need to know when new window was opened).

Thanks,

Piotr Wendykier
Reply | Threaded
Open this post in threaded view
|

Re: How to add an ActionListener to the ImageJ menu

Wayne Rasband
Plugins can implement the ImageListener interface to detect when  
image windows are opened or closed. There is an example at <http://
rsb.info.nih.gov/ij/plugins/image-listener.html>.

-wayne

On Aug 18, 2007, at 12:12 PM, Piotr Wendykier wrote:

> Hello,
>
> I'm trying to add an ActionListener to the ImageJ menu, but my code
> does not work:
>
> MenuBar menuBar = IJ.getInstance().getMenuBar();
> Menu menu = menuBar.getMenu(0);
> menu.addActionListener(new ActionListener() {
>     public void actionPerformed(ActionEvent e) {
>         //TODO
>     }
> });
>
> It looks like the only ActionListener that is added to the menu is  
> ij.ImageJ.
> In my plugin I want to respond to ImageJ menu events (in particular, I
> need to know when new window was opened).
>
> Thanks,
>
> Piotr Wendykier