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)?
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)?
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.