Capturing right click

I need to know when the mouse is right clicked on a node in the jgopalette. I have tried to implement mouselistener to my jgopalette class but it seems that none of the methods are notified. I have tried using doMouseClick which notifies me of all clicks my question is how would I know when the right mouse button has been clicked

In a JGoViewListener: public void viewChanged(JGoViewEvent evt) { if (evt.getHint() == JGoViewEvent.CLICKED && (evt.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { ... } }

For some reason the method is never called i.e. viewChanged my public boolean doMouseDblClick(int modifiers,java.awt.Point dc, java.awt.Point vc) is called but viewChanged is not.

Are you saying viewChanged (i.e. your JGoViewListener) is never, ever called? That sounds like you didn’t call JGoView.addViewListener.
A JGoViewEvent.CLICKED event is raised from JGoView.doMouseClick, if there’s an object at that point. Otherwise it calls doBackgroundClick, which raises a JGoViewEvent.BACKGROUND_CLICKED.
Or maybe the mouse moved between mouse down and mouse up, by more than two pixels, so it started some other operation instead of doing a click (by calling doMouseClick).
I wonder how your application is different from IconicApp, for example.

sorry i should have been more clear what my issue was from the start. I would like to be able to edit the nodes which are currently in the jgopalette. when the user right clicks on the node a JPopupMenu will come up. I have this class



class PopupListener extends MouseAdapter

{



public void mousePressed(MouseEvent e)

{

showPopup(e);

}



public void mouseReleased(MouseEvent e)

{

showPopup(e);

}



private void showPopup(MouseEvent e)

{

if (e.isPopupTrigger())

{

popup.show(e.getComponent(),

e.getX(), e.getY());

}

}



}

and attach a mouse listener to my nodes



node.addMouseListener(popupListener);



however the nodes are never notified. Also when I tried the same code with the JGoPalette i.e jgopal.addMouseListener(popupListener); nothing happened

Nodes and other JGoObjects are “fly-weight” objects, so they do not have listeners; how could you call addMouseListener on a JGoNode/JGoArea/JGoObject? Or did you implement this in your own node class?
The JGoViewCanvas is the actual implementer of MouseListener. So adding a MouseListener to a JGoView/JGoPalette wouldn’t accomplish what you want.
I recommend you do what I suggested in my first reply–add a JGoViewListener to your JGoPalette instance.

No youre right I cannot attach it to a node. I have tried but they are never notified. Yes I did what you suggested

adding a JGoViewListener to my JGoPalette instance. However my issue now is that my I cannot figure out how to obtain the location of the node so that the JPopupMenu appears above it. With node.getLocation I get the location of the node in terms of the palette. How would I obtain the screen location so that it appears on top of the node? Also how would I get rid of the JPopupMenu when it loses focus?

There are examples of this in the example apps: Demo1 and Flower and Processor.