Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » GridData exclude problem
GridData exclude problem [message #460413] Thu, 25 August 2005 09:13 Go to next message
hortiz Mising name is currently offline hortiz Mising name
Messages: 82
Registered: July 2009
Member
Hi,

I want to switch between two composites when clicking on a button. I use
the GridData.exclude attribute to do so. The problem is that the switch
process only works once. The snippet below illustrates this.

Thanks for your help,
Helene

package test;

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.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class SwitchableCompositeWithExclude {

private static Composite bigOne;
private static Composite smallOne;
private static Composite rightComposite;
private static Button button;

public static void main(String[] args) {

Display display = Display.getDefault ();
final Shell shell = new Shell (display);
shell.setLayout(new GridLayout(2, false));

Composite leftComposite = new Composite(shell, SWT.BORDER);
leftComposite.setLayoutData(new GridData());
leftComposite.setLayout(new GridLayout());

button = new Button(leftComposite, SWT.TOGGLE);
button.setText("Switch");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
if (button.getSelection()) {
switchComposite(1);
} else {
switchComposite(0);
}
}
});
button.setLayoutData(new GridData());

rightComposite = new Composite(shell, SWT.BORDER);
rightComposite.setLayoutData(new GridData());
rightComposite.setLayout(new GridLayout());


bigOne = new Composite(rightComposite, SWT.BORDER);
bigOne.setLayoutData(new GridData());
bigOne.setLayout(new GridLayout());

Label label;

for (int i = 0; i < 5; i++) {
label = new Label(bigOne, SWT.NONE);
label.setText("Label number " + i);
label.setLayoutData(new GridData());
}

smallOne = new Composite(rightComposite, SWT.BORDER);
smallOne.setLayoutData(new GridData());
smallOne.setLayout(new GridLayout());

label = new Label(smallOne, SWT.NONE);
label.setText("SMALL ONE !");
label.setLayoutData(new GridData());

switchComposite(0);

shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose ();
}


private static void switchComposite(int value) {
GridData smallGridData = (GridData) smallOne.getLayoutData();
GridData bigGridData = (GridData) bigOne.getLayoutData();

if (value == 0) {
System.out.println("Hiding BIG Showing SMALL");
bigGridData.exclude = true;
smallGridData.exclude = false;
} else {
System.out.println("Hiding SMALL Showing BIG");
smallGridData.exclude = true;
bigGridData.exclude = false;
}
rightComposite.layout();
rightComposite.getParent().layout();
}
}
Re: GridData exclude problem [message #460447 is a reply to message #460413] Fri, 26 August 2005 12:27 Go to previous messageGo to next message
Steve Northover is currently offline Steve Northover
Messages: 1636
Registered: July 2009
Senior Member
The problem is that exclude just excludes the widget from layout, it doesn't
hide it. Here is the relevent part of your code fixed:

private static void switchComposite(int value) {
GridData smallGridData = (GridData) smallOne.getLayoutData();
GridData bigGridData = (GridData) bigOne.getLayoutData();

if (value == 0) {
System.out.println("Hiding BIG Showing SMALL");
bigOne.setVisible (!(bigGridData.exclude = true));
smallOne.setVisible (!(smallGridData.exclude = false));
} else {
System.out.println("Hiding SMALL Showing BIG");
smallOne.setVisible (!(smallGridData.exclude = true));
bigOne.setVisible (!(bigGridData.exclude = false));
}
rightComposite.layout();
rightComposite.getParent().layout();
}

"hortiz" <hortiz@xxxxxx.xxx> wrote in message
news:50eb50ab0545a8ece877d51e872287ab$1@www.eclipse.org...
> Hi,
>
> I want to switch between two composites when clicking on a button. I use
> the GridData.exclude attribute to do so. The problem is that the switch
> process only works once. The snippet below illustrates this.
>
> Thanks for your help,
> Helene
>
> package test;
>
> 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.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Shell;
>
> public class SwitchableCompositeWithExclude {
>
> private static Composite bigOne;
> private static Composite smallOne;
> private static Composite rightComposite;
> private static Button button;
>
> public static void main(String[] args) {
>
> Display display = Display.getDefault ();
> final Shell shell = new Shell (display);
> shell.setLayout(new GridLayout(2, false));
>
> Composite leftComposite = new Composite(shell, SWT.BORDER);
> leftComposite.setLayoutData(new GridData());
> leftComposite.setLayout(new GridLayout());
>
> button = new Button(leftComposite, SWT.TOGGLE);
> button.setText("Switch");
> button.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent arg0) {
> if (button.getSelection()) {
> switchComposite(1);
> } else {
> switchComposite(0);
> }
> }
> });
> button.setLayoutData(new GridData());
>
> rightComposite = new Composite(shell, SWT.BORDER);
> rightComposite.setLayoutData(new GridData());
> rightComposite.setLayout(new GridLayout());
>
>
> bigOne = new Composite(rightComposite, SWT.BORDER);
> bigOne.setLayoutData(new GridData());
> bigOne.setLayout(new GridLayout());
>
> Label label;
>
> for (int i = 0; i < 5; i++) {
> label = new Label(bigOne, SWT.NONE);
> label.setText("Label number " + i);
> label.setLayoutData(new GridData());
> }
>
> smallOne = new Composite(rightComposite, SWT.BORDER);
> smallOne.setLayoutData(new GridData());
> smallOne.setLayout(new GridLayout());
>
> label = new Label(smallOne, SWT.NONE);
> label.setText("SMALL ONE !");
> label.setLayoutData(new GridData());
>
> switchComposite(0);
>
> shell.open();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> display.dispose ();
> }
>
>
> private static void switchComposite(int value) {
> GridData smallGridData = (GridData) smallOne.getLayoutData();
> GridData bigGridData = (GridData) bigOne.getLayoutData();
>
> if (value == 0) {
> System.out.println("Hiding BIG Showing SMALL");
> bigGridData.exclude = true;
> smallGridData.exclude = false;
> } else {
> System.out.println("Hiding SMALL Showing BIG");
> smallGridData.exclude = true;
> bigGridData.exclude = false;
> }
> rightComposite.layout();
> rightComposite.getParent().layout();
> }
> }
>
>
Re: GridData exclude problem [message #460463 is a reply to message #460447] Mon, 29 August 2005 03:32 Go to previous message
hortiz Mising name is currently offline hortiz Mising name
Messages: 82
Registered: July 2009
Member
Thanks a lot Steve, it works fine

Helene
Previous Topic:Display problem with TableViewer
Next Topic:Simple question: image on button gives red square
Goto Forum:
  


Current Time: Fri Apr 18 16:47:35 EDT 2014

Powered by FUDForum. Page generated in 0.09899 seconds