Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Snippet98 with ScrolledComposite (dynamically removing and adding children of a Composite)?
Snippet98 with ScrolledComposite (dynamically removing and adding children of a Composite)? [message #450431] |
Fri, 11 February 2005 20:42 |
Eclipse User |
|
|
|
Originally posted by: joerg.von.frantzius.artnology.nospam.com
Hi,
just in case someone immediately knows the magic trick, has anone tried
dynamically removing and adding elements to a ScrolledComposite? I got
the ScrolledComposite to show something added statically, but when I try
to change its contents dynamically, nothing gets shown. When I replace
it with a normal Composite, though, the dynamic elements are shown.
Maybe I'm just too tired right now, I'll post more details when I'm more
sure about this, just in case somebody else has stumbled over the same
problem...
|
|
|
Re: Snippet98 with ScrolledComposite (dynamically removing and adding children of a Composite)? [message #450433 is a reply to message #450431] |
Fri, 11 February 2005 21:22 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new RowLayout());
final ScrolledComposite sc = new ScrolledComposite(shell,
SWT.VERTICAL | SWT.HORIZONTAL | SWT.BORDER);
sc.setLayoutData(new RowData(300, 300));
final Composite c = new Composite(sc, SWT.NONE);
c.setLayout(new GridLayout(3, false));
for (int i = 0; i < 10; i++) {
Button b = new Button(c, SWT.PUSH);
b.setText("Button "+i);
}
sc.setContent(c);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Button b = new Button(shell, SWT.PUSH);
b.setText("Add more children");
b.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
Button b = new Button(c, SWT.PUSH);
b.setText("Another Button "+c.getChildren().length);
c.layout(false);
sc.setMinSize(c.computeSize(SWT.DEFAULT,
SWT.DEFAULT));
}
});
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
"Joerg von Frantzius" <joerg.von.frantzius@artnology.nospam.com> wrote in
message news:cuj5b6$dsb$1@www.eclipse.org...
> Hi,
>
> just in case someone immediately knows the magic trick, has anone tried
> dynamically removing and adding elements to a ScrolledComposite? I got the
> ScrolledComposite to show something added statically, but when I try to
> change its contents dynamically, nothing gets shown. When I replace it
> with a normal Composite, though, the dynamic elements are shown.
>
> Maybe I'm just too tired right now, I'll post more details when I'm more
> sure about this, just in case somebody else has stumbled over the same
> problem...
>
|
|
|
Re: Snippet98 with ScrolledComposite (dynamically removing and adding children of a Composite)? [message #450476 is a reply to message #450433] |
Sun, 13 February 2005 15:30 |
Eclipse User |
|
|
|
Originally posted by: joerg.von.frantzius.artnology.nospam.com
This is a multi-part message in MIME format.
--------------070107000005040104040202
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Stupid me was really missing the "setContent()" call when adding
components dynamically... (I dispose of the previous contents and then
wanted to set a new content Composite). The only thing particular about
ScrolledComposite, and I managed to ignore it.
Thanks a lot for your help!
Veronika Irvine schrieb:
>public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> shell.setLayout(new RowLayout());
> final ScrolledComposite sc = new ScrolledComposite(shell,
>SWT.VERTICAL | SWT.HORIZONTAL | SWT.BORDER);
> sc.setLayoutData(new RowData(300, 300));
> final Composite c = new Composite(sc, SWT.NONE);
> c.setLayout(new GridLayout(3, false));
> for (int i = 0; i < 10; i++) {
> Button b = new Button(c, SWT.PUSH);
> b.setText("Button "+i);
> }
> sc.setContent(c);
> sc.setExpandHorizontal(true);
> sc.setExpandVertical(true);
> sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
> Button b = new Button(shell, SWT.PUSH);
> b.setText("Add more children");
> b.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event e) {
> Button b = new Button(c, SWT.PUSH);
> b.setText("Another Button "+c.getChildren().length);
> c.layout(false);
> sc.setMinSize(c.computeSize(SWT.DEFAULT,
>SWT.DEFAULT));
> }
> });
> shell.pack();
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
>}
>
>"Joerg von Frantzius" <joerg.von.frantzius@artnology.nospam.com> wrote in
>message news:cuj5b6$dsb$1@www.eclipse.org...
>
>
>>Hi,
>>
>>just in case someone immediately knows the magic trick, has anone tried
>>dynamically removing and adding elements to a ScrolledComposite? I got the
>>ScrolledComposite to show something added statically, but when I try to
>>change its contents dynamically, nothing gets shown. When I replace it
>>with a normal Composite, though, the dynamic elements are shown.
>>
>>Maybe I'm just too tired right now, I'll post more details when I'm more
>>sure about this, just in case somebody else has stumbled over the same
>>problem...
>>
>>
>>
>
>
>
>
--------------070107000005040104040202
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Stupid me was really missing the "setContent()" call when adding
components dynamically... (I dispose of the previous contents and then
wanted to set a new content Composite). The only thing particular about
ScrolledComposite, and I managed to ignore it.<br>
<br>
Thanks a lot for your help!<br>
<br>
<br>
Veronika Irvine schrieb:
<blockquote cite="midcuj7mo$nt1$1@www.eclipse.org" type="cite">
<pre wrap="">public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new RowLayout());
final ScrolledComposite sc = new ScrolledComposite(shell,
SWT.VERTICAL | SWT.HORIZONTAL | SWT.BORDER);
sc.setLayoutData(new RowData(300, 300));
final Composite c = new Composite(sc, SWT.NONE);
c.setLayout(new GridLayout(3, false));
for (int i = 0; i < 10; i++) {
Button b = new Button(c, SWT.PUSH);
b.setText("Button "+i);
}
sc.setContent(c);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Button b = new Button(shell, SWT.PUSH);
b.setText("Add more children");
b.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
Button b = new Button(c, SWT.PUSH);
b.setText("Another Button "+c.getChildren().length);
c.layout(false);
sc.setMinSize(c.computeSize(SWT.DEFAULT,
SWT.DEFAULT));
}
});
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
"Joerg von Frantzius" <a class="moz-txt-link-rfc2396E" href="mailto:joerg.von.frantzius@artnology.nospam.com"><joerg.von.frantzius@artnology.nospam.com></a> wrote in
message <a class="moz-txt-link-freetext" href="news:cuj5b6$dsb$1@www.eclipse.org">news:cuj5b6$dsb$1@www.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Hi,
just in case someone immediately knows the magic trick, has anone tried
dynamically removing and adding elements to a ScrolledComposite? I got the
ScrolledComposite to show something added statically, but when I try to
change its contents dynamically, nothing gets shown. When I replace it
with a normal Composite, though, the dynamic elements are shown.
Maybe I'm just too tired right now, I'll post more details when I'm more
sure about this, just in case somebody else has stumbled over the same
problem...
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
<br>
</body>
</html>
--------------070107000005040104040202--
|
|
|
Goto Forum:
Current Time: Sat Apr 27 02:00:31 GMT 2024
Powered by FUDForum. Page generated in 0.02990 seconds
|