Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » shell - can't drive initial size
shell - can't drive initial size [message #1729786] Tue, 19 April 2016 06:06 Go to next message
Frank Bergemann is currently offline Frank BergemannFriend
Messages: 6
Registered: June 2010
Junior Member
I am using eclipse 4.4.2 with WindowBuilder to create a mini GUI.
But i can't make the initial Form show up with proper size.
Here's is a demo cut back to the essentials:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;

public class TestGui {
	
	private Display _display;
	private Shell _shell;

	private Composite _composite;
	
	private Button _btnRun;

	public TestGui() 
	{
		_display = new Display();
		
		_shell = new Shell(_display);
		_shell.setSize(283, 275);
		
		initUI(_shell);
	}

    private void initUI(Shell shell) {
		
    	shell.setLayout(new GridLayout(1, true)); 
    	
    	_composite = new Composite(shell, SWT.CENTER);
    	_composite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, true));

    	shell.layout();
    	
        Menu menuBar = new Menu(shell, SWT.BAR);
        
        {
	        MenuItem menuItem = new MenuItem(menuBar, SWT.CASCADE);
	        menuItem.setText("&File");
        
	        {
	        	Menu menue = new Menu(shell, SWT.DROP_DOWN);
	        	menuItem.setMenu(menue);

	        	{
	        		MenuItem exitItem = new MenuItem(menue, SWT.PUSH);
			        exitItem.setText("&Exit");
			        shell.setMenuBar(menuBar);
			        exitItem.addListener(SWT.Selection, event-> {
			            shell.getDisplay().dispose();
			            System.exit(0);
			        });
	        	}
        
	        }
        }

        {
	        MenuItem menuItem = new MenuItem(menuBar, SWT.CASCADE);
	        menuItem.setText("&Settings");
        
	        {
	        	Menu menu = new Menu(shell, SWT.DROP_DOWN);
	        	menuItem.setMenu(menu);

	        	{

	        		MenuItem monServerSettingsItem = new MenuItem(menu, SWT.PUSH);
	        		monServerSettingsItem.setText("&X-Server");
			        shell.setMenuBar(menuBar);
			        monServerSettingsItem.addListener(SWT.Selection, event-> {
			        });
	        	}

	        	{

	        		MenuItem dbServerSettingsItem = new MenuItem(menu, SWT.PUSH);
	        		dbServerSettingsItem.setText("&Y-Server");
			        shell.setMenuBar(menuBar);
			        dbServerSettingsItem.addListener(SWT.Selection, event-> {
			        });
	        	}

	        }
        }

    	{
    		MenuItem menuItem = new MenuItem(menuBar, SWT.CASCADE);
    		menuItem.setText("&Help");
    		
    		{
    			Menu menu = new Menu(shell, SWT.DROP_DOWN);
    			menuItem.setMenu(menu);
    		
	    		{	
		    		MenuItem about = new MenuItem(menu, SWT.PUSH);
		    		about.setText("&About");
		    		shell.setMenuBar(menuBar);
			        // shell.setMenuBar(menuBar);
		    		about.addListener(SWT.Selection, event-> {
			        });
		    	}

    		}
    	}
    	
    	{
    		_btnRun = new Button(shell, SWT.PUSH);
    		_btnRun.addSelectionListener(new SelectionAdapter() {
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    			}
    		});
    		_btnRun.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
    		_btnRun.setText("Run");
    		_btnRun.setRedraw(true);
    	}
    	
    	_composite.layout();
    	_composite.redraw();

		_shell.layout(true, true); 

		_shell.open();
		_shell.pack();

    }
    
	public void doLoop()
	{
		while (!_shell.isDisposed()) {
			if (!_shell.getDisplay().readAndDispatch()) {
				_shell.getDisplay().sleep();
			}
		}
		_shell.getDisplay().dispose();
	}

}


When i switch in eclipse to WindowBuilder "Design view" the form is too small.
It does not show the entire menu.
1. I can't resize it in the Design view.
2. When i use Test/Preview i can resize it - but the problem is that i have to resize it.

[Updated on: Tue, 19 April 2016 06:07]

Report message to a moderator

Re: shell - can't drive initial size [message #1729795 is a reply to message #1729786] Tue, 19 April 2016 07:14 Go to previous message
Frank Bergemann is currently offline Frank BergemannFriend
Messages: 6
Registered: June 2010
Junior Member
found it:
_shell.pack();

has to be dropped.
Previous Topic:Prevent tool tips from disappearing after fixed time
Next Topic:Future of SWT
Goto Forum:
  


Current Time: Mon Dec 11 04:02:19 GMT 2017

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

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