0

I'd like to retrieve a row number under the mouse cursor (as I need to display some relevant information in tooltip based on the mouse position).

I already found a way to compute the column number based on the cursor position (Why does Table.getItem(Point) always return the item from column zero?), however can't find out the row number.

final Table table = ...

table.addListener(SWT.MouseHover, new Listener() {
    @Override
    public void handleEvent(Event event) {      
        final Point point = new Point(event.x, event.y);
        final TableItem item = table.getItem(point);
        for (int i = 0; i < COLUMN_CNT; i++) {
            final Rectangle rect = item.getBounds(i);
            if (rect.contains(point)) {
                // now I'm in the right column
                ...         
            }
        }
    }
}

What would be a way to achieve that?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81

1 Answers1

1

Use the Table indexOf method:

Table table = ... your table

TableItem item = ... your item

int row = table.indexOf(item);
greg-449
  • 109,219
  • 232
  • 102
  • 145