here is another take. He finally reacts to the right click, works both in headers and in regular rows, empty tables and full tables, using only the SWT table for stocks.
This approach uses a combination of a SWT.MenuDetect listener and a "fake TableItem" created and placed only to identify the column at that position. I did not notice any unwanted visual side effects such as flicker or flash. This is likely due to the fact that the fake item is located inside the event processing before the rest of the user interface can notice its existence.
The SWT.MenuDetect listener responds to a mouse event with the right mouse button. Not very intuitive; the name suggests that it was intended primarily to regulate the appearance of the context menu, but it does its job just like a regular right-click listener. It is also emitted by the table header, unlike SWT.MouseDown. Good! Unfortunately, unlike SWT.Selection, e.widget refers to the whole table, not just columns or cells, therefore it is useless for our purposes, as it is used in the Baz answer. The column must be detected using a low-level approach with physical coordinates.
Here is the code:
import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; public class TableWithRightClickDetection { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Table with right click detection"); shell.setLayout(new FillLayout()); shell.setSize(400, 300); final Table table = new Table(shell, SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION); table.setHeaderVisible(true); table.setLinesVisible(true); int columnCount = 4; for (int i = 0; i < columnCount; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText("Column " + i); column.setMoveable(true); column.setResizable(true); table.getColumn(i).pack(); } table.addListener(SWT.MenuDetect, (e) -> {

source share