Is this a JOGL bug ???

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)
  {}
}

This is a standard problem with any lightweight object over a heavyweight canvas. There’s quite a few FAQ answers floating around with the correct lines of code you need to add to your application. Basically, you have to turn on heavyweight underlying windows.

I was already aware of the heavyweight and lightweight issue and the fix being to use

JPopupMenu.setDefaultLightWeightPopupEnabled(false); 

The line is already in my posted code :wink:
I have successfully implemented a JMenu by using this line (I actually got that answer a while back from this forum). But, I am using a JPopupmenu and I believe the problem I am seeing is different. If you run my code (assuming you get the same problem on your system) you will see that the popupmenu does actually draw over the glcanvas (proving that the setDefaultLightWeightPopupEnabled fix does work) but, as I said, only near the bottom and right edges of the glcanvas. Haven’t got a clue why this happens but it sure a’int right. If anybody has a fix and/or explanation then I would grateful.

The example program from my last post simply brings up a jframe with a blank glcanvas. Right clicking on the canvas should bring up a menu containing 3 cartoon characters at the point where you click. But, for me, it only works near the bottom and right edges of the canvas. :’(

Regards,

Sally