Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How can I get a textured button in the toolbar with SWT for cocoa?
How can I get a textured button in the toolbar with SWT for cocoa? [message #1175474] Thu, 07 November 2013 14:44 Go to next message
Hassan M. is currently offline 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:

http://i1070.photobucket.com/albums/u492/dublinus/ScreenShot2013-11-07at12457PM_zpsbb353260.png

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:

http://i1070.photobucket.com/albums/u492/dublinus/ScreenShot2013-11-07at13709PM_zpsc1425b48.png

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 #1175502 is a reply to message #1175474] Thu, 07 November 2013 15:06 Go to previous messageGo to next message
Jane Doe is currently offline Jane Doe
Messages: 1
Registered: November 2013
Junior Member
No.
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 18:09 Go to previous message
Hassan M. is currently offline 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 18:10]

Report message to a moderator

Previous Topic:Remove control from composite ?
Next Topic:BrowserFunction unable to convert returned Object array
Goto Forum:
  


Current Time: Fri Aug 22 19:46:32 EDT 2014

Powered by FUDForum. Page generated in 0.01515 seconds