Hi, after experimenting with putting a right click menu on top of an opengl canvas (glcanvas) I realised that the menu actuall does come up, but only if you right click near the bottom or near the left edge of the canvas. It works normally if I use a GLJPanel. The code below is a simple, cut down example which illustrates the problem. Has anybody got any suggestions as to how I might get around this feature as I need to get a menu to appear at the point where the user right clicks. I am using jogl under Linux, by the way (have not tested whether it works properly or not under windows).
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.java.games.jogl.*;
public class PopupTest extends JFrame implements MouseListener, GLEventListener
{
GLCanvas canvas = null;
JPopupMenu popupMenu = new JPopupMenu("my menu");
public static final Dimension PREFERRED_FRAME_SIZE = new Dimension (400, 400);
public PopupTest()
{
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
GLCapabilities capabilities = new GLCapabilities();
canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities);
this.getContentPane().add (canvas, BorderLayout.CENTER);
this.getContentPane().add(canvas);
canvas.addGLEventListener(this);
canvas.addMouseListener(this);
// add test items to the popup menu
popupMenu.add(new JMenuItem("Micky Mouse"));
popupMenu.add(new JMenuItem("Donald Duck"));
popupMenu.add(new JMenuItem("Scooby Doo"));
//needed to make the menus display over the GLCanva
}
public Dimension getPreferredSize ()
{
return PREFERRED_FRAME_SIZE;
}
public static void main(String[] args)
{
PopupTest put = new PopupTest();
put.pack();
put.setVisible(true);
}
public void mouseExited(MouseEvent me) {}
public void mouseEntered(MouseEvent me) {}
public void mouseClicked(MouseEvent me) {}
public void mouseReleased(MouseEvent me)
{
if (me.isPopupTrigger() )
{
popupMenu.show(me.getComponent(), me.getX(), me.getY());
}
}
public void mousePressed(MouseEvent me)
{
if (me.isPopupTrigger())
{
popupMenu.show(me.getComponent(), me.getX(), me.getY());
}
}
public void displayChanged (GLDrawable drawable,boolean mc, boolean dc){}
public void init (GLDrawable drawable)
{
GL gl = drawable.getGL();
gl.glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); //white
gl.glClear (GL.GL_COLOR_BUFFER_BIT);
}
public void reshape (GLDrawable drawable, int x, int y, int width, int height)
{}
public void display (GLDrawable drawable)
{}
}