Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Removing children from a canvas ruins layout
Removing children from a canvas ruins layout [message #445143] |
Tue, 26 October 2004 20:26 |
Eclipse User |
|
|
|
Originally posted by: wayneg.ananzi.co.za
Hi all
My problem is in the following section of code. The idea is to delete the
children of the canvas then create two groups on the canvas and insert
widgets into those groups. The first section ...
<code>
children = driCan.getChildren ();
for (int i = 0; i < children.length; i++) {
children [i].dispose ();
}
</code>
This line has been tested in line with some code I found on this site.
//children = new Control [0];
is what I use to empty the canvas. With this section implemented the
layout works doesn't work and the second group is drawn behind the first
group (this has been proven). When I don't implement this section the
canvas predictably doesn't refresh. It there an easier way to implement
this?
I have added more of my code for completeness.Sorry if the post is a bit
long.
Thanks
Wayne
<code>
children = driCan.getChildren ();
for (int i = 0; i < children.length; i++) {
children [i].dispose ();
}
snip snip...
FormLayout driCanLayout = new FormLayout();
driCan.setLayout(driCanLayout);
driver1 = new Group (driCan, SWT.SHADOW_ETCHED_OUT);
driver2 = new Group (driCan, SWT.SHADOW_ETCHED_OUT);
snip snip...
driver1.setText ("Driver1");
data = new FormData();
data.left= new FormAttachment(0,0);
data.top= new FormAttachment(0,0);
data.right = new FormAttachment(100,0);
data.bottom = new FormAttachment(50,-15);
driver1.setLayoutData(data);
FormLayout formLayout1 = new FormLayout();
driver1.setLayout(formLayout1);
final Blob pic = got.getBlob("pic");
final Canvas picCan = new Canvas(driver1,SWT.BORDER);
picCan.addPaintListener(new PaintListener(
) {
public void paintControl(PaintEvent e) {
try {
img = new Image(e.display,new ImageData(pic.getBinaryStream()));
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
GC g = new GC(picCan);
g.drawImage(img,0,0);
}
});
Label fname = new Label(driver1,SWT.SIMPLE);
fname.setText("Name: "+got.getString("per_fname"));
Label sname = new Label(driver1,SWT.SIMPLE);
sname.setText("Surname: "+got.getString("per_sname"));
data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(0,5);
data.right = new FormAttachment(100,-5);
data.width = 150;
data.height = 100;
picCan.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(picCan,5);
data.left = new FormAttachment(0,5);
fname.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(fname,5);
data.left = new FormAttachment(0,5);
sname.setLayoutData(data);
driver1.pack();
driver2.setText ("Driver2");
data = new FormData();
data.left= new FormAttachment(0,0);
data.top= new FormAttachment(driver1,5);
data.right = new FormAttachment(100,0);
data.bottom = new FormAttachment(100,-15);
driver2.setLayoutData(data);
FormLayout formLayout = new FormLayout();
driver2.setLayout(formLayout);
final Blob pic = got.getBlob("pic");
final Canvas picCan = new Canvas(driver2,SWT.BORDER);
picCan.addPaintListener(new PaintListener(
) {
public void paintControl(PaintEvent e) {
try {
img = new Image(e.display,new ImageData(pic.getBinaryStream()));
} catch (SQLException e1) {
// TODO Auto-generated catch block
}
GC g = new GC(picCan);
g.drawImage(img,0,0);
}
});
Label fname = new Label(driver2,SWT.SIMPLE);
fname.setText("Name: "+got.getString("per_fname"));
Label sname = new Label(driver2,SWT.SIMPLE);
sname.setText("Surname: "+got.getString("per_sname"));
data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(0,5);
data.right = new FormAttachment(100,-5);
picCan.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(picCan,5);
data.left = new FormAttachment(0,5);
fname.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(fname,5);
data.left = new FormAttachment(0,5);
sname.setLayoutData(data);
driver2.pack();
}
driCan.pack();
got.close();
</code>
|
|
|
Re: Removing children from a canvas ruins layout [message #445223 is a reply to message #445143] |
Thu, 28 October 2004 14:18 |
Steve Northover Messages: 1636 Registered: July 2009 |
Senior Member |
|
|
You are going to have to provide a complete working example in order to give
us something to debug.
"Wayne Gemmell" <wayneg@ananzi.co.za> wrote in message
news:clmbte$n1u$1@eclipse.org...
> Hi all
>
> My problem is in the following section of code. The idea is to delete the
> children of the canvas then create two groups on the canvas and insert
> widgets into those groups. The first section ...
>
> <code>
> children = driCan.getChildren ();
> for (int i = 0; i < children.length; i++) {
> children [i].dispose ();
> }
> </code>
> This line has been tested in line with some code I found on this site.
> //children = new Control [0];
>
> is what I use to empty the canvas. With this section implemented the
> layout works doesn't work and the second group is drawn behind the first
> group (this has been proven). When I don't implement this section the
> canvas predictably doesn't refresh. It there an easier way to implement
> this?
>
> I have added more of my code for completeness.Sorry if the post is a bit
> long.
>
> Thanks
> Wayne
>
> <code>
> children = driCan.getChildren ();
> for (int i = 0; i < children.length; i++) {
> children [i].dispose ();
> }
> snip snip...
>
> FormLayout driCanLayout = new FormLayout();
> driCan.setLayout(driCanLayout);
> driver1 = new Group (driCan, SWT.SHADOW_ETCHED_OUT);
> driver2 = new Group (driCan, SWT.SHADOW_ETCHED_OUT);
>
> snip snip...
>
> driver1.setText ("Driver1");
> data = new FormData();
> data.left= new FormAttachment(0,0);
> data.top= new FormAttachment(0,0);
> data.right = new FormAttachment(100,0);
> data.bottom = new FormAttachment(50,-15);
> driver1.setLayoutData(data);
>
> FormLayout formLayout1 = new FormLayout();
> driver1.setLayout(formLayout1);
> final Blob pic = got.getBlob("pic");
> final Canvas picCan = new Canvas(driver1,SWT.BORDER);
> picCan.addPaintListener(new PaintListener(
> ) {
> public void paintControl(PaintEvent e) {
> try {
> img = new Image(e.display,new ImageData(pic.getBinaryStream()));
> } catch (SQLException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
> GC g = new GC(picCan);
> g.drawImage(img,0,0);
> }
> });
>
> Label fname = new Label(driver1,SWT.SIMPLE);
> fname.setText("Name: "+got.getString("per_fname"));
> Label sname = new Label(driver1,SWT.SIMPLE);
> sname.setText("Surname: "+got.getString("per_sname"));
>
>
> data = new FormData();
> data.top = new FormAttachment(0);
> data.left = new FormAttachment(0,5);
> data.right = new FormAttachment(100,-5);
> data.width = 150;
> data.height = 100;
> picCan.setLayoutData(data);
> data = new FormData();
> data.top = new FormAttachment(picCan,5);
> data.left = new FormAttachment(0,5);
> fname.setLayoutData(data);
> data = new FormData();
> data.top = new FormAttachment(fname,5);
> data.left = new FormAttachment(0,5);
> sname.setLayoutData(data);
>
> driver1.pack();
>
>
>
> driver2.setText ("Driver2");
> data = new FormData();
> data.left= new FormAttachment(0,0);
> data.top= new FormAttachment(driver1,5);
> data.right = new FormAttachment(100,0);
> data.bottom = new FormAttachment(100,-15);
> driver2.setLayoutData(data);
>
> FormLayout formLayout = new FormLayout();
> driver2.setLayout(formLayout);
>
> final Blob pic = got.getBlob("pic");
> final Canvas picCan = new Canvas(driver2,SWT.BORDER);
> picCan.addPaintListener(new PaintListener(
> ) {
> public void paintControl(PaintEvent e) {
> try {
> img = new Image(e.display,new ImageData(pic.getBinaryStream()));
> } catch (SQLException e1) {
> // TODO Auto-generated catch block
> }
> GC g = new GC(picCan);
> g.drawImage(img,0,0);
> }
> });
> Label fname = new Label(driver2,SWT.SIMPLE);
> fname.setText("Name: "+got.getString("per_fname"));
> Label sname = new Label(driver2,SWT.SIMPLE);
> sname.setText("Surname: "+got.getString("per_sname"));
> data = new FormData();
> data.top = new FormAttachment(0);
> data.left = new FormAttachment(0,5);
> data.right = new FormAttachment(100,-5);
> picCan.setLayoutData(data);
> data = new FormData();
> data.top = new FormAttachment(picCan,5);
> data.left = new FormAttachment(0,5);
> fname.setLayoutData(data);
> data = new FormData();
> data.top = new FormAttachment(fname,5);
> data.left = new FormAttachment(0,5);
> sname.setLayoutData(data);
> driver2.pack();
>
>
> }
> driCan.pack();
> got.close();
>
>
>
> </code>
>
|
|
|
Goto Forum:
Current Time: Thu Apr 25 13:16:22 GMT 2024
Powered by FUDForum. Page generated in 0.03788 seconds
|