Java tutorial
import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; public class Main { public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new JMenuItem("One")); popupMenu.add(new JMenuItem("Two")); popupMenu.add(new JMenuItem("Three")); JList<String> list = new JList<>( new String[] { "Hello", "World", "Something", "Else", "Out", "Of", "Ideas" }); list.setComponentPopupMenu(popupMenu); f.add(list); f.pack(); f.setVisible(true); } }