javaswingjtableswingxjmenu

Unique JMenu for every column in JTable


I'm trying to add a JMenu component for every column in my JTable. The tricky bit is that I'd like the menu to be unique for each column e.g. right clicking on a column header displays a menu which is unique for the column. Anyone has an idea of how to achieve such behavior?


Solution

    1. add a MouseListener to the table header
    2. use the columnAtPoint(...) method of JTableHeader to get the column that was clicked
    3. display your menu for the specific column