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?

Use the following method to get the component renderer (renders the items on the list)
https://docs.oracle.com/javase/7/docs/api/javax/swing/JList.html#getCellRenderer()
Then fetch the component. Then attach a mouselistener, and upon right click, perform whatever action you want.
EDIT - Here's an even better way. I wasn't aware of this solution at the time of creating this answer.