Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Layouts vs. setLocation()
|
Re: Layouts vs. setLocation() [message #438741 is a reply to message #438721] |
Thu, 01 July 2004 12:16 |
Eclipse User |
|
|
|
Originally posted by: am560571.wcupa.edu
With my limited usage of SWT I found Composites do wierd things...I also
found that using SashForms is much easier...You can set the sash width to
make the resize bar bigger of smaller..and negative numbers with make it
so the user can't use it and the more negative the closer the Widgets will
be to each other. Also you get setWieghts/getWieghts method which are
good to do when/if you want to make an ini file.
later,
whatsgoingon
Ryan wrote:
> Hi!
> I have a Shell with several Composites as children. The Shell does not use
> a layout; intead, all the Composites are positioned using setLocation().
> On each Composite, however, I want to use a Layout Manager to layout all
> the widgets on the Composite.
> I found that when I do this, the children of the Composites will not
> appear. I can only use a Layout Manager on the Composites if I also use
> one on the Shell. If I position the Shell's children using setLocation(),
> I must also position the Composites' children using setLocation(). Is this
> behaviour expected? If so, why?
> Thanks!
> Ryan
|
|
| |
Re: Layouts vs. setLocation() [message #439197 is a reply to message #439062] |
Wed, 07 July 2004 03:38 |
Ryan Messages: 34 Registered: July 2009 |
Member |
|
|
Hi Steve,
Below is a stand alone snippet to illustrate. If the snippet is run as,
the label can be displayed. However, if the line marked with /*** 1 ***/
is removed, then the label can not be seen. However, I believe that the
label should still be seen even if that line is removed because the
composite has a FillLayout on it.
Thanks for your help!
Ryan
P.S. I'm running SWT 2.1. I'm not sure if this happens in 3.0.
===========
package pokemon;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class Snippet {
static Display display;
static Shell shell;
public static void main(String[] args) {
display = new Display();
shell = new Shell(display);
shell.setSize(200, 110);
Composite comp = new Composite(shell, SWT.BORDER);
comp.setSize(100,50);
comp.setLocation(5,5);
comp.setLayout(new FillLayout());
Label l = new Label(comp, SWT.NONE);
l.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
l.setBounds(2,2,20,20); /*** 1 ***/
shell.open ();
shell.forceFocus();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
=========================
Steve Northover wrote:
> Need code. How about a stand alone snippet?
> "Ryan" <a@b.com> wrote in message news:cbvrl9$neg$1@eclipse.org...
> > Hi!
> >
> > I have a Shell with several Composites as children. The Shell does not use
> > a layout; intead, all the Composites are positioned using setLocation().
> > On each Composite, however, I want to use a Layout Manager to layout all
> > the widgets on the Composite.
> >
> > I found that when I do this, the children of the Composites will not
> > appear. I can only use a Layout Manager on the Composites if I also use
> > one on the Shell. If I position the Shell's children using setLocation(),
> > I must also position the Composites' children using setLocation(). Is this
> > behaviour expected? If so, why?
> >
> > Thanks!
> >
> > Ryan
> >
|
|
|
Re: Layouts vs. setLocation() [message #439212 is a reply to message #439197] |
Wed, 07 July 2004 15:18 |
Steve Northover Messages: 1636 Registered: July 2009 |
Senior Member |
|
|
Ok, I ran your code and looked at what you are doing. Layout in SWT is only
triggered when a composite is resized or you call layout(). In your
snippet, you install the layout after you set the size. I hacked your code
to do it after and commented out the unnecessary /*** 1 ***/ line. Hope
this helps.
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class Snippet {
static Display display;
static Shell shell;
public static void main(String[] args) {
display = new Display();
shell = new Shell(display);
shell.setSize(200, 110);
Composite comp = new Composite(shell, SWT.BORDER);
// comp.setSize(100,50);
comp.setLocation(5,5);
comp.setLayout(new FillLayout());
Label l = new Label(comp, SWT.NONE);
l.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
// l.setBounds(2,2,20,20); /*** 1 ***/
comp.setSize(100, 50);
shell.open();
shell.forceFocus();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
"Ryan" <a@b.com> wrote in message news:ccfr7a$ea7$1@eclipse.org...
> Hi Steve,
>
> Below is a stand alone snippet to illustrate. If the snippet is run as,
> the label can be displayed. However, if the line marked with /*** 1 ***/
> is removed, then the label can not be seen. However, I believe that the
> label should still be seen even if that line is removed because the
> composite has a FillLayout on it.
>
> Thanks for your help!
>
> Ryan
>
> P.S. I'm running SWT 2.1. I'm not sure if this happens in 3.0.
>
> ===========
>
> package pokemon;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Shell;
>
>
> public class Snippet {
>
> static Display display;
> static Shell shell;
>
> public static void main(String[] args) {
>
> display = new Display();
> shell = new Shell(display);
> shell.setSize(200, 110);
>
> Composite comp = new Composite(shell, SWT.BORDER);
> comp.setSize(100,50);
> comp.setLocation(5,5);
>
> comp.setLayout(new FillLayout());
>
> Label l = new Label(comp, SWT.NONE);
> l.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
> l.setBounds(2,2,20,20); /*** 1 ***/
>
> shell.open ();
> shell.forceFocus();
>
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
>
> }
> }
> =========================
>
> Steve Northover wrote:
>
> > Need code. How about a stand alone snippet?
>
> > "Ryan" <a@b.com> wrote in message news:cbvrl9$neg$1@eclipse.org...
> > > Hi!
> > >
> > > I have a Shell with several Composites as children. The Shell does not
use
> > > a layout; intead, all the Composites are positioned using
setLocation().
> > > On each Composite, however, I want to use a Layout Manager to layout
all
> > > the widgets on the Composite.
> > >
> > > I found that when I do this, the children of the Composites will not
> > > appear. I can only use a Layout Manager on the Composites if I also
use
> > > one on the Shell. If I position the Shell's children using
setLocation(),
> > > I must also position the Composites' children using setLocation(). Is
this
> > > behaviour expected? If so, why?
> > >
> > > Thanks!
> > >
> > > Ryan
> > >
>
>
|
|
|
Re: Layouts vs. setLocation() [message #439215 is a reply to message #439197] |
Wed, 07 July 2004 15:24 |
Stefan Zeiger Messages: 102 Registered: July 2009 |
Senior Member |
|
|
Ryan wrote:
> the label can be displayed. However, if the line marked with /*** 1 ***/
> is removed, then the label can not be seen. However, I believe that the
> Label l = new Label(comp, SWT.NONE);
> l.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
> l.setBounds(2,2,20,20); /*** 1 ***/
The label's default size is zero. That's why it doesn't show up. If you
set a label text and pack() the Label, it will show up (even if you
don't pack() the containing Composite). If you want to position it with
the Composite's layout, you need to pack() the entire Composite. You can
still set the Composite's bounds _afterwards_ to whatever you need for
your absolute positioning.
--
Stefan Zeiger http://www.szeiger.de http://www.novocode.com
My SWT controls: http://www.novocode.com/swt
|
|
|
Re: Layouts vs. setLocation() [message #439221 is a reply to message #439212] |
Wed, 07 July 2004 16:21 |
Ryan Messages: 34 Registered: July 2009 |
Member |
|
|
Ah, I see now. Thanks, Steve!
Steve Northover wrote:
> Ok, I ran your code and looked at what you are doing. Layout in SWT is only
> triggered when a composite is resized or you call layout(). In your
> snippet, you install the layout after you set the size. I hacked your code
> to do it after and commented out the unnecessary /*** 1 ***/ line. Hope
> this helps.
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Shell;
> public class Snippet {
> static Display display;
> static Shell shell;
> public static void main(String[] args) {
> display = new Display();
> shell = new Shell(display);
> shell.setSize(200, 110);
> Composite comp = new Composite(shell, SWT.BORDER);
> // comp.setSize(100,50);
> comp.setLocation(5,5);
> comp.setLayout(new FillLayout());
> Label l = new Label(comp, SWT.NONE);
> l.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
> // l.setBounds(2,2,20,20); /*** 1 ***/
> comp.setSize(100, 50);
> shell.open();
> shell.forceFocus();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
> "Ryan" <a@b.com> wrote in message news:ccfr7a$ea7$1@eclipse.org...
> > Hi Steve,
> >
> > Below is a stand alone snippet to illustrate. If the snippet is run as,
> > the label can be displayed. However, if the line marked with /*** 1 ***/
> > is removed, then the label can not be seen. However, I believe that the
> > label should still be seen even if that line is removed because the
> > composite has a FillLayout on it.
> >
> > Thanks for your help!
> >
> > Ryan
> >
> > P.S. I'm running SWT 2.1. I'm not sure if this happens in 3.0.
> >
> > ===========
> >
> > package pokemon;
> >
> > import org.eclipse.swt.SWT;
> > import org.eclipse.swt.layout.FillLayout;
> > import org.eclipse.swt.widgets.Composite;
> > import org.eclipse.swt.widgets.Display;
> > import org.eclipse.swt.widgets.Label;
> > import org.eclipse.swt.widgets.Shell;
> >
> >
> > public class Snippet {
> >
> > static Display display;
> > static Shell shell;
> >
> > public static void main(String[] args) {
> >
> > display = new Display();
> > shell = new Shell(display);
> > shell.setSize(200, 110);
> >
> > Composite comp = new Composite(shell, SWT.BORDER);
> > comp.setSize(100,50);
> > comp.setLocation(5,5);
> >
> > comp.setLayout(new FillLayout());
> >
> > Label l = new Label(comp, SWT.NONE);
> > l.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
> > l.setBounds(2,2,20,20); /*** 1 ***/
> >
> > shell.open ();
> > shell.forceFocus();
> >
> > while (!shell.isDisposed ()) {
> > if (!display.readAndDispatch ()) display.sleep ();
> > }
> > display.dispose ();
> >
> > }
> > }
> > =========================
> >
> > Steve Northover wrote:
> >
> > > Need code. How about a stand alone snippet?
> >
> > > "Ryan" <a@b.com> wrote in message news:cbvrl9$neg$1@eclipse.org...
> > > > Hi!
> > > >
> > > > I have a Shell with several Composites as children. The Shell does not
> use
> > > > a layout; intead, all the Composites are positioned using
> setLocation().
> > > > On each Composite, however, I want to use a Layout Manager to layout
> all
> > > > the widgets on the Composite.
> > > >
> > > > I found that when I do this, the children of the Composites will not
> > > > appear. I can only use a Layout Manager on the Composites if I also
> use
> > > > one on the Shell. If I position the Shell's children using
> setLocation(),
> > > > I must also position the Composites' children using setLocation(). Is
> this
> > > > behaviour expected? If so, why?
> > > >
> > > > Thanks!
> > > >
> > > > Ryan
> > > >
> >
> >
|
|
|
Goto Forum:
Current Time: Sun Nov 10 18:21:39 GMT 2024
Powered by FUDForum. Page generated in 0.03767 seconds
|