GridLayout - GridData.exclude problem [message #695143] |
Mon, 11 July 2011 05:47 |
Ludwig Moser 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");
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08712 seconds