问题
I've already asked a question about this here, and from that question I figured out how to send messages to Objective C objects. So I did it, and I didn't see any errors, but the text of the status bar is still not being set (like it looks here). I'm using Java reflection to get the NSStatusItem
:
Tray tray = display.getSystemTray();
TrayItem item = new TrayItem(tray, SWT.NONE);
Field field = TrayItem.class.getDeclaredField("item");
field.setAccessible(true);
NSStatusItem statusItem = (NSStatusItem)field.get(item);
From SWT's source code, I can see that the item
property of TrayItem
is an NSStatusItem
. So now, statusItem
should be the NSStatusItem
of the object item
. Now I should be able to call methods on statusItem
, just like this example:
[statusItem setTitle:@"Status"];
So to do this in Java, I tried this:
if (statusItem != null) {
NSString title = NSString.stringWith("Desired Title");
OS.objc_msgSend(statusItem.id, OS.sel_setTitle_, title != null ? title.id : 0);
}
I'm using the same line of code that changes the title of an NSWindow
in SWT. Look at the setTitle
method here to see how the message is sent to the Objective C NSWindow
. This is my goal, but the text is not being set.
来源:https://stackoverflow.com/questions/14080795/cant-set-title-of-nsstatusitem-from-swt-in-java