Fix dimensions and location of windows while zooming in/out


While working with Fiji (ImageJ 1.51p) I often need to open several images taken over the same surface, tile it on the screen and zoom one of them without changing dimensions and location of the target window. However currently this seems to be not possible, as window dimensions change while I am zooming in/out

I thought it would be great to have an option or plugin to fix dimensions and location of windows while zooming in/out.

What do you think? Has this issue been already solved.

Thank you.

I found this topic on zooming and keeping window size the same.

It appears holding down the alt key and zooming will prevent the window from enlarging (but not shrinking).

This can be set in a macro using the setKeyDown(); function.

1 Like

Thank you for the suggestion — I didn’t know about Alt + Zoom combination.

Two questions here:

  1. Is this possible to write a callback macro that holds down Alt right before zooming? The idea behind this is to save Alt down behavior and prevent window enlarge for every and each zoom in?
  2. How to prevent window shrinking while zooming out?

Hi Andrey,

You could set the following code as a shortcut by adding it to your StartupMacro.fiji.ijm file found in the macros folder ( > Macros).

macro "Prevent window size increase [F1]" {
	while (!isKeyDown("space")) {

With this it will be possible to turn on the desired functionality (prevent resizing of windows while zooming in) using the specified key in the square brackets (e.g. F1 key here). The macro will stop once the space bar is pressed.

A foreseeable problem with this is that it will introduce the alt-down changes to anything that happens while the macro is active (e.g. scrolling with mouse wheel alone will go through timepoints rather than channels).

When zooming out far enough we reach a point where the image is <100% of its actual size and so the only way to prevent the canvas from becoming smaller would be to increase the canvas size with each zoom, adding in blank space around the image. While the image is >100% of its actual size, the window size will not change when zooming out.

Do you think you will still need to prevent the window from zooming out?


1 Like

Dear @AKazak,

fixing the window size during zooming of an image might be an improvement of the user experience (and could be made optional via Edit > Options > Appearance). Maybe @Wayne has an opinion on that topic as well?


Dear Stefan,

For sure fixing the window size will be great improvement of user experience. Moreover I would say that this option should be set for each window separately instead of a single setting for all windows within IJ session.

What do you think?

Dear @7rebor,

Thank you for sharing the startup macro!
I normally zoom with Ctrl + Mouse Wheel Scroll. Do you think it is possible to setKeyDown(“alt”) right after I click and hold Ctrl and deactivate it once I release Ctrl key?

As for zooming: I see the current logic. However while working with a set of tiled windows it make sense to fix position and size of each window on the display no matter what’s happening inside each windows. Otherwise it becomes a total mess if some windows become smaller / larger and automatically move around.
Do you think it is possible to write another callback script which will check sizes and locations of all windows, compare with previous and fix if necessary at each zoom event?

Hi Andrey,

The setKeyDown() and isKeyDown() functions can only work on “shift”, “space” and “alt”, not with “control”. So we can’t do the ideal macro, where it loops and looks for control key being down then sets the alt key down.

I don’t know if the windows actually move around as you say, I think the top-left of the image canvas is anchored to the same x/y coordinate on the screen. However, I do understand the shrinking window problem that can not be fixed with alt-down.

I did originally write the script you described but it started doing odd things (e.g. was not allowing any zooming to occur in some windows, and refreshing the size/location after every check of the window regardless if it had changed or not). I’ve just edited it slightly (see below), so it doesn’t constantly refresh the windows to check their dimensions.

Below are two macros that can be used as startup shortcuts in “StartupMacro.fiji.ijm”:

  • Prevent window increase - any character key can be set to turn on this macro, it will hold the alt key down until shift is pressed once, it must then be reactivated by your shortcut key (e.g. “c” in this case).
  • Resize shrunken windows - this should first be run when all images are open and tiled to save their positions/sizes. Whenever the spacebar is pressed the windows will be checked and resized. NOTE: there seems to be something wrong with resizing thin windows (i.e. aspect ratio far from 1).
macro "Prevent window size increase [c]" {
	while (!isKeyDown("shift")) {

macro "Resize shrunken windows [F3]" {
imgList = getList("image.titles"); // create array of image titles

x = newArray(imgList.length); // create a new array for size and location on screen, with enough values for all image windows 
y = newArray(imgList.length);
width = newArray(imgList.length);
height = newArray(imgList.length);
zoom = newArray(imgList.length);

for (i=0; i < imgList.length; i++) { // populate the arrays
	getLocationAndSize(x[i], y[i], width[i], height[i]);
	zoom[i] = getZoom;

for (i=0; i<2; i++) {
		while (isKeyDown("space")) {
			for (j=0; j < imgList.length; j++) { 
				newZoom = getZoom;
				if (newZoom < zoom[j]) {
					setLocation(x[j], y[j], width[j], height[j]); 

As an aside, have you considered using the hand tool to zoom? It seems much more accurate for zooming in to a particular spot when I try, which might prevent you from having to do too many zoom adjustments. Also, would using a rectangular selection to zoom in to a defined segment of the image(s) help at all?



Hi everyone!

I have tried out your suggestions, but… I still couldn’t get the window size constant while zooming out.
Normally images fit the window, so there is no borders. However, this can be changed if the borders are dragged by the mouse. Is it possible to do this through macro commands? Or any option anywhere?

I am using FIJI with ImageJ 1.51w (last version today).

My main purpose is to resize the Segmentation Editor window, so there is a gap from the image to the border. Otherwise, some of the doctors working with us, end up resizing the window and hiding part of the image…

Thanks in advance :wink:

The resizing of the entire window is frozen while zooming out if the ImagePlus window is maximized and if using Linux… but not on microsoft windows10 :S why?! Aint supose java to be “write once and run everywhere”? :slight_smile: As i am trying to develop a new plugin, i would be also happy to find out a way to embed ImagePlus in another swing.JFrame or awt.Frame that i could have more control and solve this issue for now… any idea how?
Thank you