Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » setLocation() problem
setLocation() problem [message #448990] Mon, 17 January 2005 12:31 Go to next message
No real name is currently offline No real nameFriend
Messages: 92
Registered: July 2009
Member
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 #448996 is a reply to message #448990] Mon, 17 January 2005 15:20 Go to previous messageGo to next message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
Hi Andy,

Maybe someone will be able to give helpful indications. If not, can you try
to post a full - yet not bigger than necessary - snippet that shows the
problem?

Chris
Re: setLocation() problem [message #449005 is a reply to message #448990] Mon, 17 January 2005 17:00 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
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 #449009 is a reply to message #449005] Mon, 17 January 2005 17:09 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 92
Registered: July 2009
Member
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.

I did have a quick look at ScrolledComposite but I had thought it was not
included with the Pocket PC version of SWT.

Andy

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:<csgr0o$b7t$1@www.eclipse.org>...
> 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.
Re: setLocation() problem [message #449012 is a reply to message #449009] Mon, 17 January 2005 17:51 Go to previous message
No real name is currently offline No real nameFriend
Messages: 92
Registered: July 2009
Member
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.
Previous Topic:Checkbox and non-checkbox items in a SWT tree
Next Topic:SWT Stylesheets
Goto Forum:
  


Current Time: Thu Apr 25 06:46:34 GMT 2024

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

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

Back to the top