setLocation() problem [message #448990] |
Mon, 17 January 2005 12:31 |
No real name 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 #449005 is a reply to message #448990] |
Mon, 17 January 2005 17:00 |
Veronika Irvine 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);
> }
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03765 seconds