Friday, July 21, 2006

Removing or disabling ImageJ toolbar

So, I've been playing around with ImageJ and faced the problem to remove the default toolbar. I mean, as I needed specific user interaction, I had to get rid of the useful default toolbar.
It is a nice trick. Thanks for TurboReg being open source I've got some useful ideas.
Firstly, you'll need to add some imports:

import ij.ImagePlus;
import ij.gui.ImageCanvas;
import ij.gui.ImageWindow;
import ij.gui.Toolbar;

Now, your setup method should look something like:

public int setup(String arg, ImagePlus imp) {
this.img = imp;
return DONE;

Now remove the old MouseListeners and the old Toolbar in your run method:

public void run(ImageProcessor ip) {
ImageWindow win = img.getWindow();
canvas = win.getCanvas();
for(int i=0;i
//Here, you'll add your MouseEvent handler...
//if this class handles MouseEvents implementing MouseListener, you may
// directly add 'this'

* This part will remove the old toolbar
Toolbar oldToolbar = Toolbar.getInstance();
Container container = oldToolbar.getParent();
Component[] components = container.getComponents();
for(int i=0; i<>
if(components[i] == oldToolbar){
//TODO add new toolbar here

It is a good idea to keep a copy of the old toolbar to restore it after your application finishes.
Now, enjoy your freedom, hhehe


Anonymous said...

This is a great project! Keep the good working and I may buy it for my hospital!

Best Regards, Phil.

Anonymous said...

Espero que o autor deste projeto não fique "se passando" muito.