How can I get a textured button in the toolbar with SWT for cocoa? [message #1175474] |
Thu, 07 November 2013 19:44 |
Hassan M. Messages: 9 Registered: September 2011 Location: Ohio |
Junior Member |
|
|
I've got a Java SWT application, and I'd like to get the Mac version to be as native as possible. To do this, I made a test application to test some of the controls I'd like to use in my final application. For the tool bar, I'd like a look that seems to be very common with OS X's bundled apps, like mail:
To do this with SWT, I tried writing a new constructor for ToolItem.java:
public ToolItem (ToolBar parent, int style, NSView view) {
super (parent, checkStyle (style));
this.parent = parent;
parent.createItem (this, parent.getItemCount ());
OS.objc_msgSend(nsItem.id, OS.sel_setView_, view.id);
}
This is the same as one of the existing constructors, but it takes an NSView and sets the NSToolbarItem's view to it. Then I created an NSButton and instantiated a ToolItem using the new constructor:
NSButton button = (NSButton) new SWTButton().alloc();
button.init();
button.setTitle(NSString.stringWith("Okay"));
button.setBezelStyle(11);
ToolItem toolButton = new ToolItem(toolBar, SWT.NONE, button);
The result was less than satisfactory:
As you can see, the button's size does not fit the text that was set to it. Although the top and bottom are cut off, this problem goes away when something larger (vertically) is added to the toolbar. Also, the button would disappear after a while or if the window was resized. Obviously I'm doing something wrong here. Is there a better way?
Thanks!
|
|
|
|
Re: How can I get a textured button in the toolbar with SWT for cocoa? [message #1175691 is a reply to message #1175502] |
Thu, 07 November 2013 23:09 |
Hassan M. Messages: 9 Registered: September 2011 Location: Ohio |
Junior Member |
|
|
I was really overthinking this. I found another post detailing how to add controls to the toolbar. I used the code there and was able to keep everything within SWT's system by using SWT's own buttons and other controls, which will make things a lot easier. The only downside is that I have to explicitly set the width of each element I add, which is not a huge problem for me.
The only thing I changed in SWT's source was to make the button textured. I changed line 697 (in version 4.3) from this:
button.setBezelStyle(OS.NSRoundedBezelStyle);
to this:
button.setBezelStyle(11);
[Updated on: Thu, 07 November 2013 23:10] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02984 seconds