|
|
|
|
|
Re: Change the composite [message #634099 is a reply to message #634089] |
Wed, 20 October 2010 14:02 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
|
Other way to show/hide composites using GridLayout
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
public class SampleDialog extends Dialog {
private Button firstButton;
private Button secondButton;
private Composite firstComposite;
private Composite secondComposite;
private GridData firstCompositeData;
private GridData secondCompositeData;
private Composite composite;
protected SampleDialog(Shell parentShell) {
super(parentShell);
setShellStyle(getShellStyle() | SWT.RESIZE);
}
protected Control createDialogArea(Composite parent) {
composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
firstButton = new Button(composite, SWT.RADIO);
firstButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
firstButton.setText("First");
secondButton = new Button(composite, SWT.RADIO);
secondButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
secondButton.setText("Second");
firstComposite = new Composite(composite, SWT.NONE);
firstComposite.setLayout(new GridLayout(1, false));
firstCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
firstCompositeData.horizontalSpan = 2;
firstComposite.setLayoutData(firstCompositeData);
Button button1 = new Button(firstComposite, SWT.NONE);
button1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
button1.setText("Button1");
Button button2 = new Button(firstComposite, SWT.NONE);
button2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
button2.setText("Button2");
secondComposite = new Composite(composite, SWT.NONE);
secondComposite.setLayout(new GridLayout(2, false));
secondCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
secondCompositeData.horizontalSpan = 2;
secondComposite.setLayoutData(secondCompositeData);
Button button3 = new Button(secondComposite, SWT.NONE);
button3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
button3.setText("Button3");
Button button4 = new Button(secondComposite, SWT.NONE);
button4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
button4.setText("Button4");
attachListeners();
firstButton.setSelection(true);
return composite;
}
private void attachListeners() {
SelectionListener selectionListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean isFirstVisible = firstButton.getSelection();
resetControls(isFirstVisible);
}
};
firstButton.addSelectionListener(selectionListener);
secondButton.addSelectionListener(selectionListener);
}
private void resetControls(boolean isFirstVisible) {
firstComposite.setVisible(isFirstVisible);
firstCompositeData.exclude = !isFirstVisible;
secondComposite.setVisible(!isFirstVisible);
secondCompositeData.exclude = isFirstVisible;
composite.layout();
getShell().setSize(getShell().computeSize(composite.getSize().x, SWT.DEFAULT));
}
public void create() {
super.create();
resetControls(true);
}
public static void main(String[] args) {
SampleDialog sampleDialog = new SampleDialog(null);
sampleDialog.open();
}
}
Regards,
Prasad
http://marketplace.eclipse.org/user/9964/listings
|
|
|
Powered by
FUDForum. Page generated in 0.03924 seconds