yayayokoho3
yayayokoho3

Reputation: 1199

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?

Upvotes: 1

Views: 4671

Answers (2)

keesp
keesp

Reputation: 311

If you want to be sure that the columnindex is updated prior to calling the selectionlistener, then the mousedown event will also work fine:

    table.addMouseListener( new MouseAdapter() {
        private static final long serialVersionUID = 1L;

        @Override
        public void mouseDown(MouseEvent event) {
            try {
                Point p = new Point(event.x, event.y);
                ViewerCell cell = viewer.getCell(p);
                selectedColumn = cell.getColumnIndex();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

Upvotes: 0

Tonny Madsen
Tonny Madsen

Reputation: 12718

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();
        //...
    }
});

Upvotes: 2

Related Questions