From a0d04ad10b67a33ee6fb816942c50e9dea1b4d0c Mon Sep 17 00:00:00 2001 From: Nicolas Chiaruttini Date: Sun, 29 Mar 2026 21:20:12 +0200 Subject: [PATCH] Delay creation of TaskMonitorButtonHacker component in order to set the right Look And Feel. See https://github.com/scijava/scijava-ui-swing/pull/89 --- .../java/net/imagej/legacy/IJ1Helper.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/imagej/legacy/IJ1Helper.java b/src/main/java/net/imagej/legacy/IJ1Helper.java index 338598aa..28d379f8 100644 --- a/src/main/java/net/imagej/legacy/IJ1Helper.java +++ b/src/main/java/net/imagej/legacy/IJ1Helper.java @@ -133,6 +133,7 @@ public class IJ1Helper extends AbstractContextual { /** Task bar in the main window. */ private Object taskBar; + private TaskMonitorButtonHacker taskMonitorHacker; /** Whether we are in the process of forcibly shutting down ImageJ1. */ private boolean disposing; @@ -155,14 +156,8 @@ public void initialize() { log.error(t); } - // add the task monitor icon - try { - taskBar = new TaskMonitorButtonHacker(getContext()).addTaskBar(ij1); - } - catch (final Throwable t) { - // NB: Do not let this crash ImageJ on startup! - log.error(t); - } + // NB: Task monitor icon is added later in setVisible(), + // after the Look and Feel has been initialized. if (getCommands() == null) { IJ.runPlugIn("ij.IJ.init", ""); @@ -324,6 +319,18 @@ public void setVisible(final boolean toggle) { legacyService.context().getService(SwingLookAndFeelService.class); if (lafService != null) lafService.initLookAndFeel(); + // Add the task monitor icon after the LaF is initialized, + // so that all components are created with the correct theme. + if (taskBar == null) { + try { + taskMonitorHacker = new TaskMonitorButtonHacker(getContext()); + taskBar = taskMonitorHacker.addTaskBar(ij); + } + catch (final Throwable t) { + log.error(t); + } + } + ij.pack(); } ij.setVisible(toggle);