Modifying widget attributes in callbacks

Tags: #<Tag:0x00007fd541e601b8> #<Tag:0x00007fd541e60028>


Hi ij-iers

I was wondering how I could change attributes of a Widget in a callback.

The use-case would be that a plugin has different modi, the first modus would require additional parameter and the second modus does not need any further input. So the the second modus should render the widgets for further inputs invisible or disable them to make clear, that these have no effect.

So if I have some paramter in my plugin

@Parameter(label = "modus", callback = "updateDialog")
int modus;

@Parameter(label = "parameter 1"
String param1;

protected void updateDialog() {
    if (modus == 2) {
        // Disable the widget of param1
    } else {
        // Enable the widget of param1

So how do get to the widget of param1 in the callback to disable it?


Hi Felix,

I’ve been wondering this myself sometimes, but unfortunately haven’t found out how to do it. One way to get around this would be:

private static final String DEFAULT_VALUE = "";
@Paramater(label="parameter 1", callback="enforceModus")
private String param1;

private void enforceModus() {
  if (modus == 2) {
    param1 = DEFAULT_VALUE;

One thing that complicates matters is that it’s not guaranteed that the widgets for your parameters are always the same. They change depending on the UI the Context currently uses. Furthermore, if ImageJ is running headless, there are no widgets.

Best regards,