Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Proportional resizezing using FormLayout
Proportional resizezing using FormLayout [message #441705] |
Sat, 21 August 2004 21:32 |
Peter Sommerfeld Messages: 12 Registered: July 2009 |
Junior Member |
|
|
Hi,
on a toplevel window I use a vertical sash and Formlayout
to implement a SashPane. When the window is resized
the proportion of the 2 panes shell be maintained
(simplified code below, actually I use 4 Panes and 3 sashs).
As long as the window is not resized everything works well:
The sash works as expected and the proportion of the panes
are maintained when resizing the window.
If I first resize the window and then move the sash,
the sash does not snap into the correct position but
about half an inch or less (denpending on the position)
left or right of the mouse position.
What is wrong with my code and/or what would be the
best way to achiev the intended behavior ?
Thanks in advance.
Peter
---------------------------------------------------------
public class Main{
static Display display = new Display();
static int
maxWindowWidth = 0,
maxWindowHeight = 0,
public static void main(String[] args) {
Rectangle bounds = display.getClientArea();
maxWindowWidth = bounds.width;
maxWindowHeight = bounds.height;
final Shell shell = new Shell(display);
shell.setBounds(0, 0, maxWindowWidth, maxWindowHeight);
// creating menu and toolbar omitted
// create sash and custom composites
ContentsPane leftPane = new ContentsPane(shell);
ContextPane rightPane = newContextPane(shell);
Sash sash = new Sash(shell,SWT.VERTICAL),
// set layout
int offset = 27; // on top
FormLayout layout = new FormLayout();
layout.marginWidth = 5;
layout.marginHeight = 5;
shell.setLayout(layout);
final FormData
sashData = new FormData(5, SWT.DEFAULT),
leftPaneData = new FormData(),
rightPaneData = new FormData();
leftPaneData.left = new FormAttachment(0);
leftPaneData.right = new FormAttachment(sash);
leftPaneData.top = new FormAttachment(0,offset);
leftPaneData.bottom = new FormAttachment(100);
leftPane.setLayoutData(leftPaneData);
rightPaneData.top = new FormAttachment(0,offset);
rightPaneData.left = new FormAttachment(sash);
rightPaneData.bottom = new FormAttachment(100);
rightPaneData.right = new FormAttachment(100);
rightPane.setLayoutData(rightPaneData);
sashData.left = new FormAttachment(75);
sashData.top = new FormAttachment(0,offset);
sashData.bottom = new FormAttachment(100);
sash.setLayoutData(sashData);
// add listener
sash.addListener(SWT.Selection, new Listener(){
public void handleEvent(Event event){
if(event.detail != SWT.DRAG){
int ratio = event.x /
(( leftPane.getBounds().width +
rightPane.getBounds().width) /
100);
sashData.left = new FormAttachment(ratio);
shell.layout();
}}});
// go !
shell.layout();
shell.open();
while (!shell.isDisposed())
if (!display.readAndDispatch()) display.sleep();
}
}
|
|
|
Re: Proportional resizezing using FormLayout [message #442065 is a reply to message #441705] |
Fri, 27 August 2004 15:11 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
Have a look at:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet107.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup
If this doesn't answer your question, please post some code so we can figure
out what is wrong.
"Peter Sommerfeld" <p.sommerfeld@utanet.at> wrote in message
news:cg8f5l$5jq$1@eclipse.org...
> Hi,
>
> on a toplevel window I use a vertical sash and Formlayout
> to implement a SashPane. When the window is resized
> the proportion of the 2 panes shell be maintained
> (simplified code below, actually I use 4 Panes and 3 sashs).
> As long as the window is not resized everything works well:
> The sash works as expected and the proportion of the panes
> are maintained when resizing the window.
>
> If I first resize the window and then move the sash,
> the sash does not snap into the correct position but
> about half an inch or less (denpending on the position)
> left or right of the mouse position.
>
> What is wrong with my code and/or what would be the
> best way to achiev the intended behavior ?
>
> Thanks in advance.
>
> Peter
>
> ---------------------------------------------------------
> public class Main{
>
> static Display display = new Display();
>
> static int
> maxWindowWidth = 0,
> maxWindowHeight = 0,
>
> public static void main(String[] args) {
>
> Rectangle bounds = display.getClientArea();
> maxWindowWidth = bounds.width;
> maxWindowHeight = bounds.height;
>
> final Shell shell = new Shell(display);
> shell.setBounds(0, 0, maxWindowWidth, maxWindowHeight);
>
> // creating menu and toolbar omitted
>
> // create sash and custom composites
>
> ContentsPane leftPane = new ContentsPane(shell);
> ContextPane rightPane = newContextPane(shell);
> Sash sash = new Sash(shell,SWT.VERTICAL),
>
> // set layout
>
> int offset = 27; // on top
>
> FormLayout layout = new FormLayout();
> layout.marginWidth = 5;
> layout.marginHeight = 5;
> shell.setLayout(layout);
>
> final FormData
> sashData = new FormData(5, SWT.DEFAULT),
> leftPaneData = new FormData(),
> rightPaneData = new FormData();
>
> leftPaneData.left = new FormAttachment(0);
> leftPaneData.right = new FormAttachment(sash);
> leftPaneData.top = new FormAttachment(0,offset);
> leftPaneData.bottom = new FormAttachment(100);
> leftPane.setLayoutData(leftPaneData);
>
> rightPaneData.top = new FormAttachment(0,offset);
> rightPaneData.left = new FormAttachment(sash);
> rightPaneData.bottom = new FormAttachment(100);
> rightPaneData.right = new FormAttachment(100);
> rightPane.setLayoutData(rightPaneData);
>
> sashData.left = new FormAttachment(75);
> sashData.top = new FormAttachment(0,offset);
> sashData.bottom = new FormAttachment(100);
> sash.setLayoutData(sashData);
>
> // add listener
>
> sash.addListener(SWT.Selection, new Listener(){
> public void handleEvent(Event event){
> if(event.detail != SWT.DRAG){
>
> int ratio = event.x /
> (( leftPane.getBounds().width +
> rightPane.getBounds().width) /
> 100);
>
> sashData.left = new FormAttachment(ratio);
> shell.layout();
> }}});
>
> // go !
>
> shell.layout();
> shell.open();
> while (!shell.isDisposed())
> if (!display.readAndDispatch()) display.sleep();
> }
> }
>
>
>
>
>
>
>
>
|
|
|
Re: Proportional resizezing using FormLayout [message #442067 is a reply to message #442065] |
Fri, 27 August 2004 15:29 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
Sorry, didn't see that you had already attached code.
Try the following:
sash.addListener(SWT.Selection, new Listener(){
public void handleEvent(Event event){
if(event.detail != SWT.DRAG){
Rectangle sashRect = sash.getBounds ();
Rectangle shellRect = shell.getClientArea ();
int right = shellRect.width - sashRect.width;
event.x = Math.max (Math.min (event.x, right), 0);
if (event.x != sashRect.x) {
sashData.left = new FormAttachment (event.x * 100/
shellRect.width);
shell.layout ();
}
}
}});
"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:cgnio7$5am$1@eclipse.org...
> Have a look at:
>
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet107.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup
>
> If this doesn't answer your question, please post some code so we can
figure
> out what is wrong.
>
> "Peter Sommerfeld" <p.sommerfeld@utanet.at> wrote in message
> news:cg8f5l$5jq$1@eclipse.org...
> > Hi,
> >
> > on a toplevel window I use a vertical sash and Formlayout
> > to implement a SashPane. When the window is resized
> > the proportion of the 2 panes shell be maintained
> > (simplified code below, actually I use 4 Panes and 3 sashs).
> > As long as the window is not resized everything works well:
> > The sash works as expected and the proportion of the panes
> > are maintained when resizing the window.
> >
> > If I first resize the window and then move the sash,
> > the sash does not snap into the correct position but
> > about half an inch or less (denpending on the position)
> > left or right of the mouse position.
> >
> > What is wrong with my code and/or what would be the
> > best way to achiev the intended behavior ?
> >
> > Thanks in advance.
> >
> > Peter
> >
> > ---------------------------------------------------------
> > public class Main{
> >
> > static Display display = new Display();
> >
> > static int
> > maxWindowWidth = 0,
> > maxWindowHeight = 0,
> >
> > public static void main(String[] args) {
> >
> > Rectangle bounds = display.getClientArea();
> > maxWindowWidth = bounds.width;
> > maxWindowHeight = bounds.height;
> >
> > final Shell shell = new Shell(display);
> > shell.setBounds(0, 0, maxWindowWidth, maxWindowHeight);
> >
> > // creating menu and toolbar omitted
> >
> > // create sash and custom composites
> >
> > ContentsPane leftPane = new ContentsPane(shell);
> > ContextPane rightPane = newContextPane(shell);
> > Sash sash = new Sash(shell,SWT.VERTICAL),
> >
> > // set layout
> >
> > int offset = 27; // on top
> >
> > FormLayout layout = new FormLayout();
> > layout.marginWidth = 5;
> > layout.marginHeight = 5;
> > shell.setLayout(layout);
> >
> > final FormData
> > sashData = new FormData(5, SWT.DEFAULT),
> > leftPaneData = new FormData(),
> > rightPaneData = new FormData();
> >
> > leftPaneData.left = new FormAttachment(0);
> > leftPaneData.right = new FormAttachment(sash);
> > leftPaneData.top = new FormAttachment(0,offset);
> > leftPaneData.bottom = new FormAttachment(100);
> > leftPane.setLayoutData(leftPaneData);
> >
> > rightPaneData.top = new FormAttachment(0,offset);
> > rightPaneData.left = new FormAttachment(sash);
> > rightPaneData.bottom = new FormAttachment(100);
> > rightPaneData.right = new FormAttachment(100);
> > rightPane.setLayoutData(rightPaneData);
> >
> > sashData.left = new FormAttachment(75);
> > sashData.top = new FormAttachment(0,offset);
> > sashData.bottom = new FormAttachment(100);
> > sash.setLayoutData(sashData);
> >
> > // add listener
> >
> > sash.addListener(SWT.Selection, new Listener(){
> > public void handleEvent(Event event){
> > if(event.detail != SWT.DRAG){
> >
> > int ratio = event.x /
> > (( leftPane.getBounds().width +
> > rightPane.getBounds().width) /
> > 100);
> >
> > sashData.left = new FormAttachment(ratio);
> > shell.layout();
> > }}});
> >
> > // go !
> >
> > shell.layout();
> > shell.open();
> > while (!shell.isDisposed())
> > if (!display.readAndDispatch()) display.sleep();
> > }
> > }
> >
> >
> >
> >
> >
> >
> >
> >
>
>
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 09:06:16 GMT 2024
Powered by FUDForum. Page generated in 0.03369 seconds
|