Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » getToolBar() creates a gap below the toolbar on Mac OSX
getToolBar() creates a gap below the toolbar on Mac OSX [message #823485] Sun, 18 March 2012 11:28 Go to next message
nimonic   is currently offline nimonic Friend
Messages: 6
Registered: October 2011
Junior Member
I'm using shell.getToolBar() on Mac OSX to get a native toolbar. The toolbar is being created but it is creating a gap between the bottom of the toolbar and the top of the first adjacent component. The gap increases when I increase the size of the tool items.

Is this a bug and is there a workaround?

Here is my code and attached screenshot:

package tests;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Table;

public class MacBar {

	protected Shell shell;
	private Display display;
	private Table table;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			MacBar window = new MacBar();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(450, 300);
		shell.setText("SWT Application");
		shell.setLayout(new GridLayout(1, false));
		
		ToolBar toolBar = shell.getToolBar();
		
//		ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT);
//		toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		
		ToolItem toolItem = new ToolItem(toolBar, SWT.NONE);
		Image image = new Image(display, 40, 40);
		toolItem.setImage(image);
		
		table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		table.setHeaderVisible(true);
		table.setLinesVisible(true);

	}

}

  • Attachment: MacBar.tiff
    (Size: 18.55KB, Downloaded 189 times)
Re: getToolBar() creates a gap below the toolbar on Mac OSX [message #824017 is a reply to message #823485] Mon, 19 March 2012 06:38 Go to previous messageGo to next message
Lakshmi P ShanmugamFriend
Messages: 279
Registered: July 2009
Location: India
Senior Member
Hi,

You are seeing this bug 353084

You can workaround it by excluding the toolbar from the layout using LayoutData.
For example, you could do this in your code:-

GridData gridData = new GridData();
gridData.exclude = true;
toolBar.setLayoutData(gridData);


Lakshmi P Shanmugam
Re: getToolBar() creates a gap below the toolbar on Mac OSX [message #824539 is a reply to message #824017] Mon, 19 March 2012 19:57 Go to previous message
nimonic   is currently offline nimonic Friend
Messages: 6
Registered: October 2011
Junior Member
That worked. Thank you for your help.
Previous Topic:SWT: after creating Shell isDisposed is true
Next Topic:Launch standalone app outside of eclipse
Goto Forum:
  


Current Time: Tue Apr 23 06:45:43 GMT 2024

Powered by FUDForum. Page generated in 0.03893 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top