@@ -133,6 +133,7 @@ public class IJ1Helper extends AbstractContextual {
133133
134134 /** Task bar in the main window. */
135135 private Object taskBar ;
136+ private TaskMonitorButtonHacker taskMonitorHacker ;
136137
137138 /** Whether we are in the process of forcibly shutting down ImageJ1. */
138139 private boolean disposing ;
@@ -155,14 +156,8 @@ public void initialize() {
155156 log .error (t );
156157 }
157158
158- // add the task monitor icon
159- try {
160- taskBar = new TaskMonitorButtonHacker (getContext ()).addTaskBar (ij1 );
161- }
162- catch (final Throwable t ) {
163- // NB: Do not let this crash ImageJ on startup!
164- log .error (t );
165- }
159+ // NB: Task monitor icon is added later in setVisible(),
160+ // after the Look and Feel has been initialized.
166161
167162 if (getCommands () == null ) {
168163 IJ .runPlugIn ("ij.IJ.init" , "" );
@@ -324,6 +319,18 @@ public void setVisible(final boolean toggle) {
324319 legacyService .context ().getService (SwingLookAndFeelService .class );
325320 if (lafService != null ) lafService .initLookAndFeel ();
326321
322+ // Add the task monitor icon after the LaF is initialized,
323+ // so that all components are created with the correct theme.
324+ if (taskBar == null ) {
325+ try {
326+ taskMonitorHacker = new TaskMonitorButtonHacker (getContext ());
327+ taskBar = taskMonitorHacker .addTaskBar (ij );
328+ }
329+ catch (final Throwable t ) {
330+ log .error (t );
331+ }
332+ }
333+
327334 ij .pack ();
328335 }
329336 ij .setVisible (toggle );
0 commit comments