The Ultimate Guide to Creating Compelling User Interfaces

Do more with JPopupMenu

Java Swing’s JPopupMenu is very versatile for displaying any type of information. It can be used for more than just display a popup menu. JPopupMenu inherits all the features of java.awt.Container including the ability to set a LayoutManager and add one or more arbitrary java.awt.Component.

Below are two examples demonstrating how to use a JPopupMenu to “popup” more complex components. The first show a popup with an array of buttons and the second example shows a popup whose content is a table.

Example 1: Instead of showing menu items, we can substitute them with buttons for a different look.