[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform.swt] Re: how to make a scrollable view ?
|
Hi,
The following code works for me:
public void createPartControl(Composite parent)
{
parent.setLayout(new FillLayout());
ScrolledComposite sc1 = new ScrolledComposite(parent,SWT.H_SCROLL |
SWT.V_SCROLL | SWT.BORDER);
Composite comp = new Composite(sc1, SWT.NONE);
comp.setLayout(new FillLayout());
new Label(comp, SWT.NONE).setText("text");
new Button(comp, SWT.NONE).setText("button");
sc1.setContent(comp);
comp.setSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
It displays both the label and the text.
HTH,
Regards,
Csaba
"anthony saucet" <anthony.saucet@xxxxxxxxxxx> wrote in message
news:bai5or$6aa$1@xxxxxxxxxxxxxxxx
> no change. still the view empty.
> All the examples are on a standalone window, but not with a viewPart.
> Has anybody got an idea?
> anthony
>
>
> Buddha wrote:
>
> > I think the key is to set the size of the ScrolledComposite's Content.
>
> > As the JavaDoc for ScrolledComposite states, there are two ways to use
> > ScrolledComposite. One is to set the size of the Content, and the other
is
> > to set the ScrolledComposite to expand and set the ScrolledCompsite's
> > minimum size. The following class shows both methods, just change the
> > value of "expand".
>
>
> > /* Main.java */
> > package com.cormier.tools.swt;
>
> > import org.eclipse.swt.SWT;
> > import org.eclipse.swt.custom.*;
> > import org.eclipse.swt.layout.*;
> > import org.eclipse.swt.widgets.*;
>
> > public class Main {
> > final static boolean expand = true;
> > public static void main(String[] args) {
> > Display display = new Display();
> > Shell shell = new Shell(display);
> > shell.setLayout(new FillLayout());
>
> > ViewForm form = new ViewForm(shell, SWT.DIALOG_TRIM);
> > form.setLayout(new FillLayout());
>
> > ScrolledComposite scroll = new ScrolledComposite(form, SWT.H_SCROLL |
> > SWT.V_SCROLL | SWT.BORDER);
> > scroll.setLayout(new FillLayout());
> > scroll.setBackground(display.getSystemColor(SWT.COLOR_RED));
> > scroll.setExpandHorizontal(expand);
> > scroll.setExpandVertical(expand);
> > form.setContent(scroll);
>
> > Composite comp = new Composite(scroll, SWT.NONE);
> > comp.setLayout(new RowLayout(SWT.VERTICAL));
> > new CLabel(comp, SWT.NONE).setText("This is a test Label with really
> > long text, to give us plenty of scrolling room\n\n\n\n\n\n\n\n");
> > new Text(comp, SWT.NONE).setText("This is a text control.");
> > new Button(comp, SWT.NONE).setText("This is a test Button");
> > comp.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
> > if(expand)
> > scroll.setMinSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
> > else
> > comp.setSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
> > scroll.setContent(comp);
>
> > shell.open ();
> > while (!shell.isDisposed()) {
> > if (!display.readAndDispatch ()) display.sleep ();
> > }
> > display.dispose ();
> > }
> > }
>
>
>
>