import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JTextArea; public class OldPopupMenuSample { private JPopupMenu menu; public OldPopupMenuSample() { JFrame frame = new JFrame("Old PopupMenu Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); frame.setSize(400, 100); menu = new JPopupMenu(); menu.add(new JMenuItem("item 1")); menu.add(new JMenuItem("item 2")); menu.add(new JMenuItem("item 3")); JTextArea area = new JTextArea(20, 20); area.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { popupMenu(event); } public void mouseReleased(MouseEvent event) { popupMenu(event); } }); frame.getContentPane().add(area); frame.setVisible(true); } private void popupMenu(MouseEvent event) { if (event.isPopupTrigger()) { menu.show(event.getComponent(), event.getX(), event.getY()); } } public static void main(String[] args) { new OldPopupMenuSample(); } }