Can't set title of NSStatusItem from SWT in Java

丶灬走出姿态 提交于 2020-01-05 07:51:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!