ScrolledComposite and StackLayout [message #459412] |
Tue, 09 August 2005 08:47 |
hortiz Mising name Messages: 96 Registered: July 2009 |
Member |
|
|
Hi,
I have a problem with a ScrolledComposite containing a Composite with a
StackLayout layout.
The code provided below shows the problem:
The vertical scroll bar is sized for the tallest composite within the
stack, even if a smaller one is on top.
Is this normal or should I create a ScrolledComposite for each Composite
on the stack ?
Thanks,
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
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.Shell;
import org.eclipse.swt.widgets.Text;
public class ScrollAndStack {
private static Shell shell;
private static int currentCompositeNumber = 0;
private static Composite0 composite0;
private static Composite1 composite1;
private static Composite stack;
private static ScrolledComposite scroll;
public ScrollAndStack() {
scroll = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
scroll.setExpandHorizontal(true);
scroll.setExpandVertical(true);
stack = new Composite(scroll, SWT.BORDER);
stack.setLayout(new StackLayout());
composite0 = new Composite0(stack, SWT.BORDER);
composite1 = new Composite1(stack, SWT.BORDER);
StackLayout layout = (StackLayout)stack.getLayout();
layout.topControl = composite0;
scroll.setContent(stack);
scroll.setMinSize(stack.computeSize(SWT.DEFAULT, SWT.DEFAULT));
stack.layout();
}
public static void main(String[] args) {
Display display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());
Button switchButton = new Button(shell, SWT.PUSH);
switchButton.setText("Switch");
switchButton.setLayoutData(new GridData());
switchButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (currentCompositeNumber == 0) {
StackLayout layout = (StackLayout)stack.getLayout();
layout.topControl = composite1;
currentCompositeNumber = 1;
} else {
StackLayout layout = (StackLayout)stack.getLayout();
layout.topControl = composite0;
currentCompositeNumber = 0;
}
scroll.setMinSize(stack.computeSize(SWT.DEFAULT,
SWT.DEFAULT));
stack.layout();
}
});
new ScrollAndStack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
class Composite0 extends Composite {
public Composite0(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout());
Text text;
for (int i = 0; i < 5; i++) {
text = new Text(this, SWT.NONE);
text.setText("Composite0 Text " + i);
text.setLayoutData(new GridData());
}
}
}
class Composite1 extends Composite {
public Composite1(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout());
Text text;
for (int i = 0; i < 30; i++) {
text = new Text(this, SWT.NONE);
text.setText("Composite1 Text " + i);
text.setLayoutData(new GridData());
}
}
}
}
|
|
|
Re: ScrolledComposite and StackLayout [message #459414 is a reply to message #459412] |
Tue, 09 August 2005 09:13 |
Eclipse User |
|
|
|
Originally posted by: friederich.kupzog.de
Hi Hortiz,
this is normal. The size of the StackLayout composite is alsways as big
as the biggest component. So, you answered your question yourself :)
Regards,
Friederich
hortiz wrote:
> Hi,
>
> I have a problem with a ScrolledComposite containing a Composite with a
> StackLayout layout.
>
> The code provided below shows the problem:
>
> The vertical scroll bar is sized for the tallest composite within the
> stack, even if a smaller one is on top.
>
> Is this normal or should I create a ScrolledComposite for each Composite
> on the stack ?
>
> Thanks,
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.ScrolledComposite;
> import org.eclipse.swt.custom.StackLayout;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.layout.FillLayout;
> 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.Shell;
> import org.eclipse.swt.widgets.Text;
>
> public class ScrollAndStack {
>
> private static Shell shell;
> private static int currentCompositeNumber = 0;
> private static Composite0 composite0;
> private static Composite1 composite1;
> private static Composite stack;
> private static ScrolledComposite scroll;
> public ScrollAndStack() {
> scroll = new ScrolledComposite(shell, SWT.H_SCROLL |
> SWT.V_SCROLL);
> scroll.setExpandHorizontal(true);
> scroll.setExpandVertical(true);
> stack = new Composite(scroll, SWT.BORDER);
> stack.setLayout(new StackLayout());
> composite0 = new Composite0(stack, SWT.BORDER);
> composite1 = new Composite1(stack, SWT.BORDER);
> StackLayout layout = (StackLayout)stack.getLayout();
> layout.topControl = composite0;
> scroll.setContent(stack);
> scroll.setMinSize(stack.computeSize(SWT.DEFAULT, SWT.DEFAULT));
> stack.layout();
> }
> public static void main(String[] args) {
> Display display = new Display();
> shell = new Shell(display);
> shell.setLayout(new FillLayout());
> Button switchButton = new Button(shell, SWT.PUSH);
> switchButton.setText("Switch");
> switchButton.setLayoutData(new GridData());
> switchButton.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> if (currentCompositeNumber == 0) {
> StackLayout layout = (StackLayout)stack.getLayout();
> layout.topControl = composite1;
> currentCompositeNumber = 1;
> } else {
> StackLayout layout = (StackLayout)stack.getLayout();
> layout.topControl = composite0;
> currentCompositeNumber = 0;
> }
> scroll.setMinSize(stack.computeSize(SWT.DEFAULT,
> SWT.DEFAULT));
> stack.layout();
> }
> });
> new ScrollAndStack();
> shell.pack();
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> display.dispose();
> }
> class Composite0 extends Composite {
> public Composite0(Composite parent, int style) {
> super(parent, style);
> setLayout(new GridLayout());
> Text text;
> for (int i = 0; i < 5; i++) {
> text = new Text(this, SWT.NONE);
> text.setText("Composite0 Text " + i);
> text.setLayoutData(new GridData());
> }
> }
> }
> class Composite1 extends Composite {
> public Composite1(Composite parent, int style) {
> super(parent, style);
> setLayout(new GridLayout());
> Text text;
> for (int i = 0; i < 30; i++) {
> text = new Text(this, SWT.NONE);
> text.setText("Composite1 Text " + i);
> text.setLayoutData(new GridData());
> }
> }
> }
> }
>
>
>
>
>
>
--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel 0241 160696-1
Fax 0221 726670
www.kupzog.de/fkmk
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02264 seconds