Skip to content

Commit a0d04ad

Browse files
committed
Delay creation of TaskMonitorButtonHacker component in order to set the right Look And Feel. See scijava/scijava-ui-swing#89
1 parent f678a54 commit a0d04ad

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/main/java/net/imagej/legacy/IJ1Helper.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)