Issues with Tree.getItem(Point) and Table.getItem(Point) [message #460545] |
Wed, 31 August 2005 10:21  |
Eclipse User |
|
|
|
Hi
I use tables and trees (multi column) and I have a mouse listener
attached to them. It is supposed to return the item on which the
user clicked (right click even in multiselect, so selection is not
helpful).
I use the following code to figure out the item (somewhat shortened):
// get the mouse position (absolute on the screen)
Point mousePosition = control.getDisplay().getCursorLocation();
// get the top left coordinate fo the table (absolute on the screen)
Point tablePosition = table.getParent().toDisplay(table.getLocation());
// relative position = absolute position - top left corner of table
Point relativePosition = new Point(
mousePosition.x - tablePosition.x,
mousePosition.y - tablePosition.y);
// now use the position relative in the table to fetch the item
TableItem item = table.getItem(relPos);
For tables this works perfectly. However, doing the same with a tree,
I always get the item below the one that I actually clicked on.
The "Offset" is exactly the height of one row.
Where does this offset come from? How can it be explained? Is it a bug?
BTW: For some other reasons I cannot use the mouse event providing the
mouse coordinates as the entire code above is located inside an Action
object (run() method).
Thanks
Michael Pellaton
|
|
|
Re: Issues with Tree.getItem(Point) and Table.getItem(Point) [message #460760 is a reply to message #460545] |
Tue, 06 September 2005 20:50  |
Eclipse User |
|
|
|
This is a bug. Please enter a bug report. Thanks!
"Michael Pellaton" <newsgroups@pellaton.li> wrote in message
news:4315BCF6.2060707@pellaton.li...
> Hi
>
> I use tables and trees (multi column) and I have a mouse listener
> attached to them. It is supposed to return the item on which the
> user clicked (right click even in multiselect, so selection is not
> helpful).
>
> I use the following code to figure out the item (somewhat shortened):
>
>
> // get the mouse position (absolute on the screen)
> Point mousePosition = control.getDisplay().getCursorLocation();
>
> // get the top left coordinate fo the table (absolute on the screen)
> Point tablePosition = table.getParent().toDisplay(table.getLocation());
>
> // relative position = absolute position - top left corner of table
> Point relativePosition = new Point(
> mousePosition.x - tablePosition.x,
> mousePosition.y - tablePosition.y);
>
> // now use the position relative in the table to fetch the item
> TableItem item = table.getItem(relPos);
>
>
> For tables this works perfectly. However, doing the same with a tree,
> I always get the item below the one that I actually clicked on.
>
> The "Offset" is exactly the height of one row.
>
> Where does this offset come from? How can it be explained? Is it a bug?
>
> BTW: For some other reasons I cannot use the mouse event providing the
> mouse coordinates as the entire code above is located inside an Action
> object (run() method).
>
> Thanks
>
> Michael Pellaton
|
|
|
Powered by
FUDForum. Page generated in 0.08467 seconds