开发者

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

My question is H开发者_开发技巧ow can we find the currently selected column number in the selected row of a SWT Table in Eclipse RCP?


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜