Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ScrolledComposite and StackLayout
ScrolledComposite and StackLayout [message #459412] Tue, 09 August 2005 08:47 Go to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: ScrolledComposite and StackLayout [message #459416 is a reply to message #459414] Tue, 09 August 2005 09:35 Go to previous messageGo to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Thanks Friederich for your answer

Helene
Re: ScrolledComposite and StackLayout [message #459558 is a reply to message #459416] Wed, 10 August 2005 15:57 Go to previous message
Joe Pusateri is currently offline Joe PusateriFriend
Messages: 2
Registered: July 2009
Junior Member
--____MFYVKBDZBDVYBGCLQMQX____
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline; modification-date="Thu, 10 Aug 2005 05:57:03
-0500"

I didn't like the empty white space left from the largest component when =
the smallest was displayed, so each time I change the stack, I recompute =
the size of the current composite and tell the scrolledComposite the new =
height. (In my case the width doesn't change.)

m_scrolledComposite.setMinHeight(computeSize(SWT.DEFAULT, =
SWT.DEFAULT).y);

Joe
--____MFYVKBDZBDVYBGCLQMQX____
Content-Type: multipart/related; boundary="____PGJMUKIBGYUINCFOMJHW____"


--____PGJMUKIBGYUINCFOMJHW____
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="Text.htm";
modification-date="Thu, 10 Aug 2005 05:57:03 -0500"

<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-8859-1"=
>
<META content=3D"MSHTML 6.00.2800.1515" name=3DGENERATOR></HEAD>
<BODY style=3D"MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>I didn't like the empty white space left from the largest component =
when the smallest was displayed, so each time I change the stack, I =
recompute the size of the current composite and tell the scrolledComposite =
the new height.&nbsp; (In my case the width doesn't change.)</DIV>
<DIV>&nbsp;</DIV>
<DIV> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; m_scrolledComposite.setMinH=
eight(computeSize(SWT.DEFAULT, SWT.DEFAULT).y);</DIV>
<DIV>&nbsp;</DIV>
<DIV>Joe<BR></DIV></BODY></HTML>
--____PGJMUKIBGYUINCFOMJHW____--

--____MFYVKBDZBDVYBGCLQMQX____--
Previous Topic:dynamically adding jars to the classpath
Next Topic:OleControlSite shell.explorer - detect or intercept alert dialogs
Goto Forum:
  


Current Time: Thu Mar 28 10:23:57 GMT 2024

Powered by FUDForum. Page generated in 0.02264 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top