Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Issues with Tree.getItem(Point) and Table.getItem(Point)
Issues with Tree.getItem(Point) and Table.getItem(Point) [message #460545] Wed, 31 August 2005 14:21 Go to next message
Michael Pellaton is currently offline Michael PellatonFriend
Messages: 289
Registered: July 2009
Senior Member
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] Wed, 07 September 2005 00:50 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
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
Previous Topic:SWT Optimization Problem
Next Topic:Why after scroll down getSelection value is 0 ?
Goto Forum:
  


Current Time: Fri Apr 26 01:33:15 GMT 2024

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

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

Back to the top