简体   繁体   中英

JFace tableViewer checkbox selection returns null in eclipse e4

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM