简体   繁体   中英

How do you specify to display a diamond in a NSMenuItem (minimized window indicator)?

I'm creating a JNI to display an application wide menu bar instead of the JFrame specific one. This allows me to keep a menubar displayed even when no JFrames are present. I've hit a small snag, in my window menu I can't figure out how to display a diamond for the windows that are minimized. As far as I can tell in the standard API there's only three states available On, Off, and Mixed where mixed is a dash. Is there a way to show the minimized diamond using standard API? Or am I going to have to create a diamond image and use that?

AppKit isn't using a public API to get this image. It's using _NSGetThemeImage which pulls an image out of the old HIToolbox Appearance Manager theme resources and converts it an NSImage. I wan't able to find an equivalent public API.

If you want to mimic how AppKit does it, use:

NSImage* _NSGetThemeImage(int num);

[menuitem setState:NSOnState];
[menuitem setOnStateImage:_NSGetThemeImage(155)];

Better yet, use this code to grab the NSImage, save it to a TIFF file, and then include that TIFF in your program. That way you avoid using private APIs in the shipping code. I doubt Apple would complain that you're stealing their diamond. ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM