Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to create button on runtime?
How to create button on runtime? [message #504525] Sun, 20 December 2009 23:28 Go to next message
Wok Show is currently offline Wok Show
Messages: 40
Registered: July 2009
Member
hello everybody,

i try to make buttons via buttonlistener, how doesn't it work?

please help.

	public void createPartControl(Composite parent) {
		parent.setLayout(new GridLayout(1, false));
		
		GridData mainLayoutData = new GridData();
		mainLayoutData.widthHint=3000;
		mainLayoutData.grabExcessHorizontalSpace=true;
		
		final Composite mainContainer = new Composite(parent, SWT.BORDER);
		mainContainer.setLayoutData(mainLayoutData);
		mainContainer.setLayout(new GridLayout());
		
		GridData gameLayoutData = new GridData();
		gameLayoutData.widthHint=3000;
		gameLayoutData.heightHint=3000;
		gameLayoutData.grabExcessHorizontalSpace=true;
		gameLayoutData.grabExcessVerticalSpace=true;
		
		final Composite gameContainer = new Composite(parent, SWT.BORDER);
		gameContainer.setLayoutData(gameLayoutData);
		
		Button addCardButton = new Button(mainContainer, SWT.PUSH);
		addCardButton.addSelectionListener(new SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				new Button(gameContainer, SWT.PUSH);
				
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				
				
			}
		});
		
	}
Re: How to create button on runtime? [message #504528 is a reply to message #504525] Sun, 20 December 2009 23:41 Go to previous messageGo to next message
Wok Show is currently offline Wok Show
Messages: 40
Registered: July 2009
Member
p.s. i forget to set the Layout for gameContainer, but with this setting, it still doesn't work. are there any update problems?
Re: How to create button on runtime? [message #504565 is a reply to message #504528] Mon, 21 December 2009 09:31 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2148
Registered: July 2009
Senior Member
For the Button created in the the SelectionListener to be shown you need to
follow it with "gameContainer.layout()". Layouts only happen for free in
swt on resize.

Grant


"Chau" <d.chau1982@yahoo.de> wrote in message
news:hgnfse$4iu$1@build.eclipse.org...
> p.s. i forget to set the Layout for gameContainer, but with this setting,
it still doesn't work. are there any update problems?
Re: How to create button on runtime? [message #504611 is a reply to message #504525] Mon, 21 December 2009 13:35 Go to previous messageGo to next message
Wok Show is currently offline Wok Show
Messages: 40
Registered: July 2009
Member
hi grant, can you please explain that exactly for me. i can't instance new buttons on the container. i have set the gameContainer a gridlayout...but nothing happens.
Re: How to create button on runtime? [message #504664 is a reply to message #504611] Mon, 21 December 2009 18:35 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 415
Registered: September 2009
Senior Member
Chau wrote:
> hi grant, can you please explain that exactly for me. i can't instance
> new buttons on the container. i have set the gameContainer a
> gridlayout...but nothing happens.
He is saying that, after You create Your button, after You set the
GridLayout, just before You return, You should call
"gameContainer.layout()".
If You forget this crucial step Your container will *not* be repainted,
so no button will appear.

HiH
Mauro
Re: How to create button on runtime? [message #504687 is a reply to message #504525] Mon, 21 December 2009 22:14 Go to previous messageGo to next message
Wok Show is currently offline Wok Show
Messages: 40
Registered: July 2009
Member
ok ir works, thanks a lot grant and mauro
Re: How to create button on runtime? [message #504733 is a reply to message #504525] Tue, 22 December 2009 01:11 Go to previous message
Wok Show is currently offline Wok Show
Messages: 40
Registered: July 2009
Member
hi, now i have another question. if i dispose a control with the button in the gamecontainer, how can i instanciate new controlls in this container ?
Previous Topic:Automatic restart of crashed OLE Object
Next Topic:direct access to swt classes' fields
Goto Forum:
  


Current Time: Sun Jul 13 20:25:36 EDT 2014

Powered by FUDForum. Page generated in 0.01617 seconds