Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » GridLayout - GridData.exclude problem(bug or my fault?)
icon4.gif  GridLayout - GridData.exclude problem [message #695143] Mon, 11 July 2011 05:47 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i ran into a problem with gridlayout griddata.exclude.
i created a small sample application which shows my problem.

i create an app with 3 buttons lets call em b1, b2, b3;
add an action listeners to b2 which sets its griddata.exclude to true;
add an action listener to b1 which sets the griddata.exclude from b2 to false;

this should hide the b2 when its clicked and show it again when b1 is clicked.
what happens is this:
when i click b2, then b3 disappears.
when i click b1, b3 gets shown again.

whats wrong?

package listTests;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class TestGui {

	protected Shell shell;
	private Button btn3;
	private Button btn2;
	private Button btn1;

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

	/**
	 * Open the window.
	 */
	public void open() {
		Display 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));


		btn1 = new Button(shell, SWT.NONE);
		btn1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		btn1.setText("Show ALL");
		btn1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				GridData gd = (GridData) btn2.getLayoutData();
				gd.exclude = false;
				btn2.setLayoutData(gd);
				shell.layout();
			}
		});

		btn2 = new Button(shell, SWT.NONE);
		btn2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		btn2.setText("Press me to hide");
		btn2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				GridData gd = (GridData) btn2.getLayoutData();
				gd.exclude = true;
				btn2.setLayoutData(gd);
				shell.layout();
			}
		});

		btn3 = new Button(shell, SWT.NONE);
		btn3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		btn3.setText("New Button");
	}
}
Re: GridLayout - GridData.exclude problem [message #695151 is a reply to message #695143] Mon, 11 July 2011 06:07 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
finally found my mistake by looking at snippet175

i had to add
btn2.setVisible(!gd.exclude);

after gd.exclude = xxx

although i am not sure why i need to set visibility, as its already done by the layout. looks like strange behaviour to me.
Re: GridLayout - GridData.exclude problem [message #696350 is a reply to message #695151] Wed, 13 July 2011 17:35 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
On 7/11/11 2:07 AM, Ludwig Moser wrote:
> finally found my mistake by looking at snippet175
>
> i had to add
>
> btn2.setVisible(!gd.exclude);
>
> after gd.exclude = xxx
>
> although i am not sure why i need to set visibility, as its already done
> by the layout. looks like strange behaviour to me.


For future reference, such questions would be best placed in the SWT
forum group.

Eric
Previous Topic:addActionListeners method undefined que from a newb
Next Topic:Company installation
Goto Forum:
  


Current Time: Fri Apr 26 10:18:16 GMT 2024

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

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

Back to the top