Home » Eclipse Projects » Eclipse Platform » SWT: try to hide/show widgets without success(trying to use GridLayout to hide and show widgets without success)
SWT: try to hide/show widgets without success [message #780092] |
Tue, 17 January 2012 07:04 |
He Heng Huang Messages: 4 Registered: January 2012 |
Junior Member |
|
|
Newbi questions.
I laid the widgets in a 2 column gridlayout, and when user click a checkbox, I want to hide or show one line of the widgets. Tried many times, no success. Code as below:
BTW, are there any other methods to hide/show composites or other controls by using SSWT?
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Just for testing");
GridLayout layout = new GridLayout(2, false);
shell.setLayout(layout);
Label label = new Label(shell, SWT.None);
label.setText("User:");
GridData data1 = new GridData(80, SWT.DEFAULT);
label.setLayoutData(data1);
Text text = new Text(shell, SWT.SINGLE);
GridData data2 = new GridData(150, SWT.DEFAULT);
data2.horizontalAlignment = GridData.BEGINNING;
text.setLayoutData(data2);
new Label(shell, SWT.None).setText("");
Button b = new Button(shell, SWT.CHECK);
b.setText("Add more strings???????????");
final Label dlabel = new Label(shell, SWT.None);
dlabel.setText("Description:");
final Text dtext = new Text(shell, SWT.MULTI);
final GridData hide = new GridData(0, 0);
hide.exclude = true;
dtext.setLayoutData(hide);
dlabel.setLayoutData(hide);
label = new Label(shell, SWT.None);
label.setText("User:");
data1 = new GridData(80, SWT.DEFAULT);
label.setLayoutData(data1);
text = new Text(shell, SWT.SINGLE);
data2 = new GridData(150, SWT.DEFAULT);
data2.horizontalAlignment = GridData.BEGINNING;
text.setLayoutData(data2);
final GridData ldata = new GridData(80, SWT.DEFAULT);
final GridData rdata = new GridData(150, 50);
b.addListener(SWT.Selection, new Listener(){
public void handleEvent(Event e){
if(dtext.getLayoutData() == hide){
dlabel.setLayoutData(ldata);
dtext.setLayoutData(rdata);
dlabel.setVisible(true);
dtext.setVisible(true);
}else{
dlabel.setLayoutData(hide);
dtext.setLayoutData(hide);
dlabel.setVisible(false);
dtext.setVisible(false);
}
shell.layout();
}
});
shell.setSize(300, 400);
shell.open();
while(!shell.isDisposed()){
if(display.readAndDispatch()) display.sleep();
}
Help please, thanks a lot.
|
|
|
Re: SWT: try to hide/show widgets without success [message #780655 is a reply to message #780092] |
Wed, 18 January 2012 21:53 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
(note that there's an eclipse.platform.swt newsgroup for swt-specific
questions like this)
The following example snippets should be helpful:
-
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet98.java
-
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet175.java
-
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet249.java
HTH,
Grant
On 1/17/2012 2:04 AM, He Heng Huang wrote:
> Newbi questions.
>
> I laid the widgets in a 2 column gridlayout, and when user click a
> checkbox, I want to hide or show one line of the widgets. Tried many
> times, no success. Code as below:
>
> BTW, are there any other methods to hide/show composites or other
> controls by using SSWT?
>
>
> Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setText("Just for testing");
> GridLayout layout = new GridLayout(2, false);
> shell.setLayout(layout);
>
> Label label = new Label(shell, SWT.None);
> label.setText("User:");
> GridData data1 = new GridData(80, SWT.DEFAULT);
> label.setLayoutData(data1);
> Text text = new Text(shell, SWT.SINGLE);
> GridData data2 = new GridData(150, SWT.DEFAULT);
> data2.horizontalAlignment = GridData.BEGINNING;
> text.setLayoutData(data2);
>
> new Label(shell, SWT.None).setText("");
> Button b = new Button(shell, SWT.CHECK);
> b.setText("Add more strings???????????");
>
> final Label dlabel = new Label(shell, SWT.None);
> dlabel.setText("Description:");
> final Text dtext = new Text(shell, SWT.MULTI);
> final GridData hide = new GridData(0, 0);
> hide.exclude = true;
> dtext.setLayoutData(hide);
> dlabel.setLayoutData(hide);
>
> label = new Label(shell, SWT.None);
> label.setText("User:");
> data1 = new GridData(80, SWT.DEFAULT);
> label.setLayoutData(data1);
> text = new Text(shell, SWT.SINGLE);
> data2 = new GridData(150, SWT.DEFAULT);
> data2.horizontalAlignment = GridData.BEGINNING;
> text.setLayoutData(data2);
>
> final GridData ldata = new GridData(80, SWT.DEFAULT);
> final GridData rdata = new GridData(150, 50);
>
> b.addListener(SWT.Selection, new Listener(){
> public void handleEvent(Event e){
> if(dtext.getLayoutData() == hide){
> dlabel.setLayoutData(ldata);
> dtext.setLayoutData(rdata);
> dlabel.setVisible(true);
> dtext.setVisible(true);
> }else{
> dlabel.setLayoutData(hide);
> dtext.setLayoutData(hide);
> dlabel.setVisible(false);
> dtext.setVisible(false);
> }
>
> shell.layout();
> }
> });
>
> shell.setSize(300, 400);
> shell.open();
> while(!shell.isDisposed()){
> if(display.readAndDispatch()) display.sleep();
> }
>
>
>
> Help please, thanks a lot.
|
|
|
Goto Forum:
Current Time: Wed Apr 24 15:18:51 GMT 2024
Powered by FUDForum. Page generated in 0.02863 seconds
|