Skip to main content



      Home
Home » Eclipse Projects » GEF » how to get the location of an image in a label?
how to get the location of an image in a label? [message #167922] Fri, 11 February 2005 23:15 Go to next message
Eclipse UserFriend
Originally posted by: yabing.crimsonlogic.com

Hi,

I am trying to create connections between two labels, which are decorated
with images. I use the following method to create the labels:

Label label = new Label("text", new Image(d, "d:\\mapitem_field.gif"));

now I want to get the location of the image in the label so that I can
make it as the anchor point for the connection between the labels.
currently I am using the follwing method to get the location:

Rectangle r = getOwner().getBounds().getCopy();
// return the rectangel of the label
return r.getRight();

can anyone tell me how I can revise the code above to get the location of
the image in the label? Thanks so much!

Yabing
Re: how to get the location of an image in a label? [message #167941 is a reply to message #167922] Sat, 12 February 2005 07:11 Go to previous messageGo to next message
Eclipse UserFriend
Yabing,

Without thinking too much, this should give you the bounds of the image.

Rectangle r = ((Label)getOwner()).getIcon().getBounds();

Hope this helps,
Brian.

yabing chen wrote:

> Hi,

> I am trying to create connections between two labels, which are decorated
> with images. I use the following method to create the labels:

> Label label = new Label("text", new Image(d, "d:\mapitem_field.gif"));

> now I want to get the location of the image in the label so that I can
> make it as the anchor point for the connection between the labels.
> currently I am using the follwing method to get the location:

> Rectangle r = getOwner().getBounds().getCopy();
> // return the rectangel of the label
> return r.getRight();

> can anyone tell me how I can revise the code above to get the location of
> the image in the label? Thanks so much!

> Yabing
Re: how to get the location of an image in a label? [message #168051 is a reply to message #167941] Sun, 13 February 2005 21:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yabing.crimsonlogic.com

Hi Brian,

instead of org.eclipse.draw2d.geometry.Rectangle, the method
((Label)getOwner()).getIcon().getBounds() returns an instance of
org.eclipse.swt.graphics.Rectangle, which always returns x and y values of
0.
so i still don't know how I can get the position of the image rectangle
object.

Thanks,
Yabing


Brian Fernandes wrote:

> Yabing,

> Without thinking too much, this should give you the bounds of the image.

> Rectangle r = ((Label)getOwner()).getIcon().getBounds();

> Hope this helps,
> Brian.

> yabing chen wrote:

>> Hi,

>> I am trying to create connections between two labels, which are decorated
>> with images. I use the following method to create the labels:

>> Label label = new Label("text", new Image(d, "d:mapitem_field.gif"));

>> now I want to get the location of the image in the label so that I can
>> make it as the anchor point for the connection between the labels.
>> currently I am using the follwing method to get the location:

>> Rectangle r = getOwner().getBounds().getCopy();
>> // return the rectangel of the label
>> return r.getRight();

>> can anyone tell me how I can revise the code above to get the location of
>> the image in the label? Thanks so much!

>> Yabing
Re: how to get the location of an image in a label? [message #168074 is a reply to message #168051] Sun, 13 February 2005 22:12 Go to previous messageGo to next message
Eclipse UserFriend
yabing,
Sorry, I checked the code right now and I you should use
Label#getIconBounds

That would make it
Rectangle r = ((Label)getOwner()).getIconBounds();

Hope that checks out :)
Brian.

yabing chen wrote:

> Hi Brian,

> instead of org.eclipse.draw2d.geometry.Rectangle, the method
> ((Label)getOwner()).getIcon().getBounds() returns an instance of
> org.eclipse.swt.graphics.Rectangle, which always returns x and y values of
> 0.
> so i still don't know how I can get the position of the image rectangle
> object.

> Thanks,
> Yabing


> Brian Fernandes wrote:

>> Yabing,

>> Without thinking too much, this should give you the bounds of the image.

>> Rectangle r = ((Label)getOwner()).getIcon().getBounds();

>> Hope this helps,
>> Brian.

>> yabing chen wrote:

>>> Hi,

>>> I am trying to create connections between two labels, which are decorated
>>> with images. I use the following method to create the labels:

>>> Label label = new Label("text", new Image(d, "d:mapitem_field.gif"));

>>> now I want to get the location of the image in the label so that I can
>>> make it as the anchor point for the connection between the labels.
>>> currently I am using the follwing method to get the location:

>>> Rectangle r = getOwner().getBounds().getCopy();
>>> // return the rectangel of the label
>>> return r.getRight();

>>> can anyone tell me how I can revise the code above to get the location of
>>> the image in the label? Thanks so much!

>>> Yabing
Re: how to get the location of an image in a label? [message #168106 is a reply to message #167922] Sat, 12 February 2005 02:33 Go to previous messageGo to next message
Eclipse UserFriend
label.getIconBounds()

"yabing chen" <yabing@crimsonlogic.com> wrote in message
news:cujvtv$eju$1@www.eclipse.org...
> Hi,
>
> I am trying to create connections between two labels, which are decorated
> with images. I use the following method to create the labels:
>
> Label label = new Label("text", new Image(d, "d:\\mapitem_field.gif"));
>
> now I want to get the location of the image in the label so that I can
> make it as the anchor point for the connection between the labels.
> currently I am using the follwing method to get the location:
>
> Rectangle r = getOwner().getBounds().getCopy();
> // return the rectangel of the label
> return r.getRight();
>
> can anyone tell me how I can revise the code above to get the location of
> the image in the label? Thanks so much!
>
> Yabing
>
Re: how to get the location of an image in a label? [message #168168 is a reply to message #168074] Mon, 14 February 2005 01:45 Go to previous message
Eclipse UserFriend
Originally posted by: yabing.crimsonlogic.com

Hi Brian,

Yeah, Now it is ok. thanks so much!

Yabing

Brian Fernandes wrote:

> yabing,
> Sorry, I checked the code right now and I you should use
> Label#getIconBounds

> That would make it
> Rectangle r = ((Label)getOwner()).getIconBounds();

> Hope that checks out :)
> Brian.

> yabing chen wrote:

>> Hi Brian,

>> instead of org.eclipse.draw2d.geometry.Rectangle, the method
>> ((Label)getOwner()).getIcon().getBounds() returns an instance of
>> org.eclipse.swt.graphics.Rectangle, which always returns x and y values of
>> 0.
>> so i still don't know how I can get the position of the image rectangle
>> object.

>> Thanks,
>> Yabing


>> Brian Fernandes wrote:

>>> Yabing,

>>> Without thinking too much, this should give you the bounds of the image.

>>> Rectangle r = ((Label)getOwner()).getIcon().getBounds();

>>> Hope this helps,
>>> Brian.

>>> yabing chen wrote:

>>>> Hi,

>>>> I am trying to create connections between two labels, which are decorated
>>>> with images. I use the following method to create the labels:

>>>> Label label = new Label("text", new Image(d, "d:mapitem_field.gif"));

>>>> now I want to get the location of the image in the label so that I can
>>>> make it as the anchor point for the connection between the labels.
>>>> currently I am using the follwing method to get the location:

>>>> Rectangle r = getOwner().getBounds().getCopy();
>>>> // return the rectangel of the label
>>>> return r.getRight();

>>>> can anyone tell me how I can revise the code above to get the location of
>>>> the image in the label? Thanks so much!

>>>> Yabing
Previous Topic:My DirectEdit works only if I override the DirectEditManager.commit() method?!
Next Topic:draw2d: mousedragged and draw rectangle
Goto Forum:
  


Current Time: Tue Jun 24 16:36:25 EDT 2025

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

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

Back to the top