setLocation() problem [message #448990] |
Mon, 17 January 2005 07:31  |
Eclipse User |
|
|
|
I'm fairly new to SWT, I'm working on an app for the pocket pc, although
the problem I have is not specific to this.
I have nested two composites to create a scrolling form. The outer
composite uses SWT.NO_FOCUS | SWT.V_SCROLL and fills and grabs
horizontally and vertically. Inside is a gridlayout.
The inner composite is filling horizontally with
GridData(SWT.FILL,SWT.NONE,true,false). So my form fills the width of
the composite and is whatever length it needs to be.
The problem I am having is that when the shell (and thus the outer
composite) is resized the inner composite jumps back to location (0,0)
in spite of the scrollbar position. I ran a debug session and the
setLocation call is setting the co-ordinates, but these are just ignored.
Does anyone know what might cause this? Maybe the timing of when
setLocation method is called? Otherwise my event handler for the actual
scrolling is working correctly.
many thanks,
Andy
My listener is below (topScroller is outer, topPane is inner)
//resize listener
topScroller.addListener (SWT.Resize, new Listener () {
public void handleEvent (Event e) {
Point size = topPane.getSize ();
Rectangle rect = topScroller.getClientArea();
vBar.setMaximum (size.y);
vBar.setThumb (Math.min (size.y, rect.height));
int vPage = size.y - rect.height;
int vSelection = vBar.getSelection();
Point location = topPane.getLocation();
if (vSelection >= vPage) {
if (vPage <= 0) vSelection = 0;
location.y = -vSelection;
}
topPane.setLocation (location);
}
|
|
|
|
Re: setLocation() problem [message #449005 is a reply to message #448990] |
Mon, 17 January 2005 12:00   |
Eclipse User |
|
|
|
You can not combine a Layout with calls to setLocation/setSize/setBounds.
When you use a Layout you are relegating the sizing and positioning of the
children to the Layout. It is undefined what will happen when you start
calling setLocation on the children. If you wish to have scrolled content
in a composite and also use a Layout, you must manage the scrolling in one
composite and apply the Layout to a second composite inside. See
ScrolledComposite for an example of how to do this.
"Andy Harrison" <andyh@agaricus.co.uk> wrote in message
news:csgd1b$c5b$1@www.eclipse.org...
> I'm fairly new to SWT, I'm working on an app for the pocket pc, although
> the problem I have is not specific to this.
>
> I have nested two composites to create a scrolling form. The outer
> composite uses SWT.NO_FOCUS | SWT.V_SCROLL and fills and grabs
> horizontally and vertically. Inside is a gridlayout.
>
> The inner composite is filling horizontally with
> GridData(SWT.FILL,SWT.NONE,true,false). So my form fills the width of the
> composite and is whatever length it needs to be.
>
> The problem I am having is that when the shell (and thus the outer
> composite) is resized the inner composite jumps back to location (0,0) in
> spite of the scrollbar position. I ran a debug session and the setLocation
> call is setting the co-ordinates, but these are just ignored.
>
> Does anyone know what might cause this? Maybe the timing of when
> setLocation method is called? Otherwise my event handler for the actual
> scrolling is working correctly.
>
> many thanks,
> Andy
>
> My listener is below (topScroller is outer, topPane is inner)
>
> //resize listener
> topScroller.addListener (SWT.Resize, new Listener () {
> public void handleEvent (Event e) {
> Point size = topPane.getSize ();
> Rectangle rect = topScroller.getClientArea();
> vBar.setMaximum (size.y);
> vBar.setThumb (Math.min (size.y, rect.height));
> int vPage = size.y - rect.height;
> int vSelection = vBar.getSelection();
> Point location = topPane.getLocation();
>
> if (vSelection >= vPage) {
> if (vPage <= 0) vSelection = 0;
> location.y = -vSelection;
> }
> topPane.setLocation (location);
> }
|
|
|
|
Re: setLocation() problem [message #449012 is a reply to message #449009] |
Mon, 17 January 2005 12:51  |
Eclipse User |
|
|
|
Thanks Veronika, that works a treat. I just set the width of the inner
composite with "outer.getSize().x" with no scrollbar and
"outer.getClientArea.width" when the scrollbar is visible. This has the same
effect as grabbing the horizontal space in my old GridLayout.
cheers,
Andy
"Andy Harrison" <andyh@agaricus.co.uk> wrote in message
news:csgtb6$o55$1@www.eclipse.org...
> sure, thanks, I will try manually setting the width of the inner composite
> when the shell is resized. I won't set a layout inside the scrolling
> composite and see what I get.
|
|
|
Powered by
FUDForum. Page generated in 1.08061 seconds