문제

I am using tableviewer with Check box style in the following way

tableViewer = new TableViewer(parent, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER| SWT.CHECK);

I used the following code to listen to tableviewer. I know it is wrong because it listens to the selection and not to check box selection.

 tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
           @Override
           public void selectionChanged(SelectionChangedEvent event) {
             IStructuredSelection selection = (IStructuredSelection)tableViewer.getSelection();
             Object firstElement = selection.getFirstElement();
             System.out.println("firstElement"+firstElement);
             // Do something with it
           }
         }); 

I need to listen to checkbox selection in JFace TableViewer.

Thanks in advance

도움이 되었습니까?

해결책

The selection listener on a check box table still responds to normal row selection, it does not respond to clicking the check boxes.

To add a listener for check box changes you need to use CheckboxTableViewer and use the addCheckStateListener method.

CheckboxTableViewer also has many helper methods for managing the check box states.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top