JPopUpMenu above GLCanvas under MacOS when using a LookAndFeel

hello,

i am placing a JPopUpMenu with heavyweight enabled above a GLCanvas. while this works fine under windows it does not show up correctly under MacOS because the JPopUPMenu seems to be below the GLCanvas although it is heavyweight.

when no LookAndFeel is set it seems to use the mac-look (aqua) then it works. but i definitely must use a lookandfeel like metal, motif, etc.

both OSes have java 6u7, latest jogl, latest drivers.

is there any possiblity to have a JPopUpMenu above a GLCanvas under MacOS? thanks!

I haven’t tried doing anything like that, but can you post some test code. If I have time, I can try fiddling around with it (and verify that it happens on my Mac as well).

Don’t do it! Sometimes it doesn’t work even under Windows, that is why I wrote some classes to display menus in JOGL without using nor AWT neither Swing. Look at my class main.GLMenu.java.

lhkbob, yes i will provide a test case soon.

goussej, i looked at your class, it seems you are basically doing a menu directly in opengl. this is actually what i have now, and want to get rid of, since the swing-layout managers are much more flexible.

ok, here is the testcase that reproduces this error on Mac. just run and compile with jogl on classpath and click in the window, so that the popup is half above the glcanvas.

please note, that i am forcing the metal-lookandfeel. it seems to work on the standard-mac-lookandfeel which looks like this aqua thingy.

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.sun.opengl.util.Animator;


public class PopupTest implements GLEventListener {

	public static void main(String [] args) {
		JPopupMenu.setDefaultLightWeightPopupEnabled(false);
		try {
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}
		new PopupTest();
	}
	
	
	public PopupTest() {
		JFrame frame = new JFrame("hello");
		frame.setSize(400, 400);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JSplitPane splitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);		
		frame.add(splitpane);
		
		
		final JPanel top = new JPanel(new GridLayout(1, 1));
		splitpane.setRightComponent(top);
		top.setMinimumSize(new Dimension(100,100));
		top.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				JPopupMenu menu = new JPopupMenu("popup");
				menu.setLayout(new BorderLayout());
				JLabel biglabel = new JLabel("<html>some
text
with
line
breaks</html>");
				menu.add(biglabel, BorderLayout.CENTER);
				menu.show(top, e.getX(), e.getY()-100);
			}			
		});
		
		
		JPanel bottom = new JPanel(new GridLayout(1, 1));
		splitpane.setLeftComponent(bottom);
		bottom.setMinimumSize(new Dimension(100,100));
		GLCanvas canvas = new GLCanvas(new GLCapabilities());		
		bottom.add(canvas);
		canvas.addGLEventListener(this);
		canvas.setMinimumSize(new Dimension(100,100));
		
		Animator animator = new Animator(canvas);
		animator.start();
		
		
		frame.setVisible(true);
		splitpane.setDividerLocation(0.5);
	}

	float a = 0;
	@Override
	public void display(GLAutoDrawable arg0) {
		GL gl = arg0.getGL();
		gl.glClearColor(0,(float) (Math.sin(a)+1)*0.3f,0,0);
		gl.glClear(GL.GL_COLOR_BUFFER_BIT);
		a += 0.01f;
	}


	@Override
	public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {}


	@Override
	public void init(GLAutoDrawable arg0) {}


	@Override
	public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {}
	
}

I know Swing is more flexible but I had some problems of flickering, the Swing popup menu was not usable under Microsoft Windows Vista.

Well, at the very least I confirmed your behavior that metal does indeed fail. Have you tried using another LaF that java comes with (ocean or whatever its called–not Mac’s aqua). Otherwise my guess is that Mac’s implementation is buggy and they haven’t bothered fixing it because they figured everyone would use their aqua laf.

yes, from all the LAFs i have tried all fail besides the aqua one.

to me it seems that this
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
is just ignored by the jvm implementation of apple.