Skip to main content


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] Mon, 21 December 2009 04:28 Go to next message
Wok Show is currently offline Wok ShowFriend
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] Mon, 21 December 2009 04:41 Go to previous messageGo to next message
Wok Show is currently offline Wok ShowFriend
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 14:31 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
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 18:35 Go to previous messageGo to next message
Wok Show is currently offline Wok ShowFriend
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 23:35 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
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] Tue, 22 December 2009 03:14 Go to previous messageGo to next message
Wok Show is currently offline Wok ShowFriend
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 06:11 Go to previous message
Wok Show is currently offline Wok ShowFriend
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: Fri Apr 19 15:17:13 GMT 2024

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

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

Back to the top