2

What is the best way to add the Checkmark (tick) to the active window's MenuItem on the Window menu?

Is there a standard icon to do this (and the diamond for a minimized window)?

Lyndon
  • 573
  • 6
  • 24
  • [continuation here](http://stackoverflow.com/questions/10502844/java-swing-osx-window-menu-icon-alignment) – mKorbel May 08 '12 at 17:24

1 Answers1

3

There's a great article on getting the OS X system specific icons here:

http://nadeausoftware.com/articles/2008/12/mac_java_tip_how_access_mac_specific_nsimage_icons

The icon that you want for this is the "checkmark" and you can get it with this:

final Icon checkmarkIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage( "NSImage://NSMenuOnStateTemplate" ));

Then, you want to add that Icon as the selectedIcon in your JMenuItem:

JMenuItem myOSXMenuItem = new JMenuItem("My Menu Item");
myOSXMenuItem.setSelectedIcon(checkmarkIcon);

You can manually maintain this menu and the checkmark state when you open new windows in your application by adding/removing items from your Window menu, and by setting the current window using the setSelected() method on your menu items.

Dave
  • 106
  • 2
  • 11
  • Thanks Dave, I'll try that over the next few days (very busy on unrelated tasks at the moment)... – Lyndon Jun 24 '12 at 10:34