I want to display a JPopupMenu
on right click on elements of a JList
.
jList.setComponentPopupMenu(...)
works fine and displays the context menu (JPopupMenu
) if I right click the JList
.
But my JList
often is larger (taller) than needed for its entries (as the JList is expanded to window height).
And the context menu always appears, even if I click on the blank area of the JList.
I want the context-menu (JPopupMenu) to only show up, if the user right-clicks an entry, not if the user clicks on the blank space below the last list entry.
The menu options are only applicable to a certain entry, not to the JList
in its entirety.
I tried setComponentPopupMenu
on a custom ListCellRenderer
instead of on the list but that doesn't show a menu at all.
How could I get an only-on-entry context menu for my JList?