JPopupMenu Example Java Swing

JPopupMenu Example Java Swing

A JPopupMenu appears anywhere on the screen when a right mouse button is clicked. Following program creates your own popup menu with your choicest menu items.

Here, left mouse click does not generate any event. Popup menu appears on the frame when a right mouse button is clicked and that too at the same point of click.

Example on JPopupMenu

Output screenshot on JPopupMenu Example Java Swing


addSeparator() method adds a dull colored line in between the menu items. This is useful to separate the items with a common functionality.


Differentiates right click from left mouse click.

e.getX( ), e.getY()

getX() and getY() are the methods of MouseEvent that return the x and y coordinates on the frame where the mouse click takes place.