We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Popup menu (Read 1179 times)
Popup menu
Jan 4th, 2006, 11:52am
 
Hi,

Is it possible to show popup menu by right click our mouse(by using PApplet & if yes, then how) ?
Re: Popup menu
Reply #1 - Jan 4th, 2006, 1:39pm
 
you'd have to write your own class as far as i know, or import a free java-library if you can find one.. but be careful with right-clicks, mac-users only have one mousebutton.. shift-click or something works on both.

-seltar
Re: Popup menu
Reply #2 - Jan 4th, 2006, 5:47pm
 
Create a JPopupMenu in method setup() as follows:

import javax.swing.*;
import java.awt.event.*;

void setup() {

final JPopupMenu menu = new JPopupMenu();
   
   // Create and add a menu item
   JMenuItem item = new JMenuItem("Item Label 1");
   item.addActionListener(new ActionListener() {
       void actionPerformed(ActionEvent e) {
           System.out.println("Item Label 1");
       }
   });
   menu.add(item);
   item = new JMenuItem("Item Label 2");
   menu.add(item);
   
   // Set the component to show the popup menu
   addMouseListener(new MouseAdapter() {        
       public void mouseReleased(MouseEvent evt) {
           if (evt.isPopupTrigger()) {
               menu.show(evt.getComponent(), evt.getX(), evt.getY());
           }
       }
   });
}
Page Index Toggle Pages: 1