Search code examples
numbersswtrcp

How can I get the column number in a SWT table in Eclipse RCP?


My question is How can we find the currently selected column number in the selected row of a SWT Table in Eclipse RCP?


Solution

  • Inside a Listener - e.g. for SWT.Selection - you can use viewer.getCell(...) as illustrated in the following example:

    myTableViewer.getTable().addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            Point p = new Point(event.x, event.y);
            ViewerCell cell = myTableViewer.getCell(p);
            int columnIndex = cell.getColumnIndex();
            //...
        }
    });