Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Resize a composite dynamically(How to resize a composite dynamically and retain the "center" alignment)
Resize a composite dynamically [message #482365] Wed, 26 August 2009 11:25 Go to next message
Madhu Samuel is currently offline Madhu SamuelFriend
Messages: 199
Registered: July 2009
Senior Member
Hello folks,

Please find the attached LayoutEg.java.

I have created a canvas and resized it dynamically. But after the resize the new resized canvas is not centralized.

I resize the canvas using the setSize() method of the canvas.

How can I maintain the 'center' alignment after resize of canvas?

Help is appreciated.

Regards,
Madhu


Re: Resize a composite dynamically [message #482671 is a reply to message #482365] Thu, 27 August 2009 13:54 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
Your attachment seems to be missing. Hopefully it's simple enough to just
be pasted as plaintext?

Grant


"Madhu Samuel" <madhusamuel@gmail.com> wrote in message
news:h73635$n1v$1@build.eclipse.org...
> Hello folks,
>
> Please find the attached LayoutEg.java.
>
> I have created a canvas and resized it dynamically. But after the resize
the new resized canvas is not centralized.
>
> I resize the canvas using the setSize() method of the canvas.
>
> How can I maintain the 'center' alignment after resize of canvas?
>
> Help is appreciated.
>
> Regards,
> Madhu
Re: Resize a composite dynamically [message #482699 is a reply to message #482671] Thu, 27 August 2009 15:02 Go to previous messageGo to next message
Madhu Samuel is currently offline Madhu SamuelFriend
Messages: 199
Registered: July 2009
Senior Member
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class LayoutEg {

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
GridLayout gridLayout = new GridLayout ();
shell.setLayout (gridLayout);

Canvas canvas0 = new Canvas (shell, SWT.BORDER);
GridData data = new GridData (SWT.CENTER, SWT.BEGINNING, true, true);
data.widthHint = 10;
canvas0.setLayoutData (data);

shell.pack ();
shell.open ();

System.out.println("shell opened");
delay();

canvas0.setSize(50, 50);
System.out.println("redrawn");

while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
display.dispose ();
}

private static void delay() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}


Re: Resize a composite dynamically [message #482910 is a reply to message #482699] Fri, 28 August 2009 14:16 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
After canvas0.setSize(50,50) you need to add:

data = (GridData)canvas0.getLayoutData();
data.widthHint = data.heightHint = 50;
shell.layout();

Grant


"Madhu Samuel" <madhusamuel@gmail.com> wrote in message
news:h7675t$ccn$1@build.eclipse.org...
> import org.eclipse.swt.*;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
>
> public class LayoutEg {
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> GridLayout gridLayout = new GridLayout ();
> shell.setLayout (gridLayout);
>
> Canvas canvas0 = new Canvas (shell, SWT.BORDER);
> GridData data = new GridData (SWT.CENTER, SWT.BEGINNING, true, true);
> data.widthHint = 10;
> canvas0.setLayoutData (data);
>
> shell.pack ();
> shell.open ();
>
> System.out.println("shell opened");
> delay();
>
> canvas0.setSize(50, 50);
> System.out.println("redrawn");
>
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ())
> display.sleep ();
> }
> display.dispose ();
> }
>
> private static void delay() {
> try {
> Thread.sleep(1000);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> }
> }
Re: Resize a composite dynamically [message #482911 is a reply to message #482910] Fri, 28 August 2009 14:19 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
Correction: REPLACE "canvas0.setSize(50,50)" with the three lines I
mentioned. When a control is being laid out by a parent's layout, setting
the control's size isn't useful because the layout will just re-set it the
next time it's run.

Grant


"Grant Gayed" <grant_gayed@ca.ibm.com> wrote in message
news:h78or3$k60$1@build.eclipse.org...
> After canvas0.setSize(50,50) you need to add:
>
> data = (GridData)canvas0.getLayoutData();
> data.widthHint = data.heightHint = 50;
> shell.layout();
>
> Grant
>
>
> "Madhu Samuel" <madhusamuel@gmail.com> wrote in message
> news:h7675t$ccn$1@build.eclipse.org...
> > import org.eclipse.swt.*;
> > import org.eclipse.swt.graphics.Point;
> > import org.eclipse.swt.layout.*;
> > import org.eclipse.swt.widgets.*;
> >
> > public class LayoutEg {
> >
> > public static void main (String [] args) {
> > Display display = new Display ();
> > Shell shell = new Shell (display);
> > GridLayout gridLayout = new GridLayout ();
> > shell.setLayout (gridLayout);
> >
> > Canvas canvas0 = new Canvas (shell, SWT.BORDER);
> > GridData data = new GridData (SWT.CENTER, SWT.BEGINNING, true, true);
> > data.widthHint = 10;
> > canvas0.setLayoutData (data);
> >
> > shell.pack ();
> > shell.open ();
> >
> > System.out.println("shell opened");
> > delay();
> >
> > canvas0.setSize(50, 50);
> > System.out.println("redrawn");
> >
> > while (!shell.isDisposed ()) {
> > if (!display.readAndDispatch ())
> > display.sleep ();
> > }
> > display.dispose ();
> > }
> >
> > private static void delay() {
> > try {
> > Thread.sleep(1000);
> > } catch (InterruptedException e) {
> > e.printStackTrace();
> > }
> > }
> > }
>
>
Re: Resize a composite dynamically [message #483089 is a reply to message #482365] Mon, 31 August 2009 05:04 Go to previous message
Madhu Samuel is currently offline Madhu SamuelFriend
Messages: 199
Registered: July 2009
Senior Member
Thanks Grant... It works now!

I completely forgot about calling "shell.layout()".. I was looking for refresh, redraw methods.. Smile


Previous Topic:Accessibility for Custom Controls
Next Topic:Background application is getting activated.
Goto Forum:
  


Current Time: Mon Aug 19 23:15:21 GMT 2019

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

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

Back to the top