ScrolledComposite [message #455948] |
Mon, 23 May 2005 23:54 |
Eclipse User |
|
|
|
Originally posted by: waynetg.telkomsa.net
Hi all,
I have an array of buttons that doesn't fit on a Composite. Instead I'm
trying to use a ScrolledComposite. Below is a simplified working
snippet. Could somebody please tell me why only one of the buttons in the
snippet shows up on the shell? The original was a custom Composite but the
effect seems to be the same on a stand alone app.
Thanks
Tshwala
<code>
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
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 Test {
public static void main(String[] Args)
{
Display disp = new Display();
Shell shell = new Shell(disp);
shell.setLayout(new FillLayout());
ScrolledComposite sc1 = new ScrolledComposite (shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridLayout gl = new GridLayout();
gl.numColumns = 4;
sc1.setLayout(gl);
Button button2 = new Button (sc1, SWT.PUSH);
button2.setText ("Button 1");
button2.setSize (400, 400);
sc1.setContent (button2);
Button button1 = new Button (sc1, SWT.PUSH);
button1.setText ("Button 1");
button1.setSize (400, 400);
sc1.setContent (button1);
sc1.layout();
shell.layout();
shell.open();
while(!shell.isDisposed())
if (!disp.readAndDispatch())
disp.sleep();
disp.dispose();
}
}
</code>
|
|
|
|
Re: ScrolledComposite [message #455961 is a reply to message #455954] |
Tue, 24 May 2005 09:20 |
Eclipse User |
|
|
|
Originally posted by: waynetg.telkomsa.net
On Tue, 24 May 2005 09:07:21 +0200, Stefan Pietsch wrote:
> Hi,
>
> you have to use another Composite as the Content of your ScolledComposite
> and than insert the buttons in the Composite instead of the
> ScrolledComposite!
>>
Thanks but that didn't work :( I've included a new snippet with the new
advice included. I just get an empty page. Removing the line
sc1.setContent (comp); gives me scrollbars but they have nothing in them.
<code>
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite; import
org.eclipse.swt.layout.FillLayout; 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.Shell;
public class Test {
public static void main(String[] Args)
{
Display disp = new Display();
Shell shell = new Shell(disp);
shell.setLayout(new FillLayout());
final ScrolledComposite sc1 = new ScrolledComposite (shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
sc1.setLayout(new FillLayout());
Composite comp = new Composite(sc1,SWT.NONE);
GridLayout gl = new GridLayout();
gl.numColumns = 4;
comp.setLayout(gl);
Button button1 = new Button (comp, SWT.PUSH);
button1.setText ("Button 1");
button1.setSize (100, 100);
Button button2 = new Button (comp, SWT.PUSH);
button2.setText ("Button 2");
button2.setSize (100, 100);
comp.layout();
sc1.setContent (comp);
sc1.layout();
shell.layout();
shell.open();
while(!shell.isDisposed())
if (!disp.readAndDispatch())
disp.sleep();
disp.dispose();
}
}
</code>
|
|
|
Re: ScrolledComposite [message #456045 is a reply to message #455961] |
Wed, 25 May 2005 07:02 |
Stefan Pietsch Messages: 68 Registered: July 2009 |
Member |
|
|
Hi,
you have to call ScrolledComposite.setSize or ScrolledComposite.setMinSize.
Take a look at the API-documentation of ScrolledComposite. There you find an
example how to use ScrolledComposite (two methods of using).
Bye Stefan
"Tshwala" <waynetg@telkomsa.net> schrieb im Newsbeitrag
news:pan.2005.05.24.09.20.44.750590@telkomsa.net...
> On Tue, 24 May 2005 09:07:21 +0200, Stefan Pietsch wrote:
> > Hi,
> >
> > you have to use another Composite as the Content of your
ScolledComposite
> > and than insert the buttons in the Composite instead of the
> > ScrolledComposite!
> >>
> Thanks but that didn't work :( I've included a new snippet with the new
> advice included. I just get an empty page. Removing the line
> sc1.setContent (comp); gives me scrollbars but they have nothing in them.
>
> <code>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.ScrolledComposite; import
> org.eclipse.swt.layout.FillLayout; 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.Shell;
>
> public class Test {
> public static void main(String[] Args)
> {
> Display disp = new Display();
> Shell shell = new Shell(disp);
>
> shell.setLayout(new FillLayout());
> final ScrolledComposite sc1 = new ScrolledComposite (shell,
SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
> sc1.setLayout(new FillLayout());
>
> Composite comp = new Composite(sc1,SWT.NONE);
>
> GridLayout gl = new GridLayout();
> gl.numColumns = 4;
> comp.setLayout(gl);
>
> Button button1 = new Button (comp, SWT.PUSH);
> button1.setText ("Button 1");
> button1.setSize (100, 100);
>
> Button button2 = new Button (comp, SWT.PUSH);
> button2.setText ("Button 2");
> button2.setSize (100, 100);
>
> comp.layout();
>
> sc1.setContent (comp);
>
> sc1.layout();
> shell.layout();
> shell.open();
>
> while(!shell.isDisposed())
> if (!disp.readAndDispatch())
> disp.sleep();
> disp.dispose();
>
> }
> }
> </code>
|
|
|
Re: ScrolledComposite [message #456151 is a reply to message #456045] |
Wed, 25 May 2005 18:21 |
Eclipse User |
|
|
|
Originally posted by: waynetg.telkomsa.net
On Wed, 25 May 2005 09:02:20 +0200, Stefan Pietsch wrote:
> you have to call ScrolledComposite.setSize or ScrolledComposite.setMinSize.
> Take a look at the API-documentation of ScrolledComposite. There you find an
> example how to use ScrolledComposite (two methods of using).
Thanks :)
|
|
|
Powered by
FUDForum. Page generated in 0.29021 seconds