Add a scrollbar to GenericDialog

I have a fairly long GenericDialog (in vertical direction) - which does not fit on the computer screen.

My idea was to add a vertical scrollbar to the parent frame of the GenericDialog in ImageJ.
Can this be done and if how?

Stephan

Edit: Clarifications added as suggested by Herbie by email.

Hi Stephan,

You can take example on the method addScrollBars from this custom class EnhanceGenericDialog, you would need to make a custom dialog class extending the GenericDialog class though to define this custom method.
Otherwise you could directly use the EnhancedGenericDialog class as such if you can, and you agree to the licence terms.

I dont remember exactly why you can’t really add the scrollbars to the parent frame before filling up the dialog, in the case above, they rather iterate over the GUI elements and add them to a new scrollable pane, while preserving the macro-recording…

1 Like

Hi @LThomas -

so in essence GenericDialog doesn’t support scrollbars.

My code (Java plugin) will be distributed under GPLv3, so I simply can use the EnhancedGenericDialog class?

Stephan

Indeed, it’s a very handy class but the absence of scrollbars is one limitation. Maybe it could be adressed in the future. But it’s a bit of work since it’s taking into account screen size…

Sure, you can also acknowledge the Sholl Analysis project from which this class belong if you want.

1 Like

Okay interesting @LThomas.

Herbie (suggested per email) to keep the dialog small to not be overwhelming for the user. I agree. I could now restructure my single large dialog into multiple dialogs.

While we are at it, some side question: Am I missing any newer Java API for ImageJ? I heard people speaking in the past about an easier to use Java API, but I couldn’t find information on that.

That’s also an option however you loose the advantage of the macro-recording, the first dialog would be recorded but then when called the command would display the following GUIs.

For GUI you can use also script parameters in scripting languages, with the advantage that the GUI becomes automatically scrollable when too large.
In a Java classes this can be achieved by writing an ImageJ2 plugin, and using the scijava parameters annotations.
See the StarDist plugin for an example.

The script parameters works in ImageJ2/Fiji but not in a simple ImageJ1 installation though.

1 Like