Skip to content

Commit edd19c7

Browse files
committed
Fix menu separators not rendering on macOS native menu bar
1 parent 4063620 commit edd19c7

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/main/java/org/scijava/ui/swing/script/GuiUtils.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,13 @@ static void addMenubarSeparator(final JMenu menu, final String header) {
319319
menu.addSeparator();
320320
}
321321
try {
322+
if (usesScreenMenuBar()) {
323+
// The native macOS menu bar only translates menu items, not arbitrary components
324+
final JMenuItem item = new JMenuItem(header);
325+
item.setEnabled(false);
326+
menu.add(item);
327+
return;
328+
}
322329
final JLabel label = new JLabel(" "+ header);
323330
label.setEnabled(false);
324331
label.setForeground(getDisabledComponentColor());
@@ -328,6 +335,11 @@ static void addMenubarSeparator(final JMenu menu, final String header) {
328335
}
329336
}
330337

338+
/** Whether menu bars are displayed in the native macOS menu bar (at the top of the screen) */
339+
private static boolean usesScreenMenuBar() {
340+
return PlatformUtils.isMac() && Boolean.parseBoolean(System.getProperty("apple.laf.useScreenMenuBar"));
341+
}
342+
331343
static void addPopupMenuSeparator(final JPopupMenu menu, final String header) {
332344
if (menu.getComponentCount() > 1) {
333345
menu.addSeparator();

0 commit comments

Comments
 (0)