views:

242

answers:

2

I'm working with an application that draws on a GLCanvas. I'd like to add a "floating menu" on top of it (something I would do in Swing by adding a menu to the glass pane). Since GLCanvas doesn't extend Container, what would be the suggested way to do this?

thanks,

Jeff

A: 

GLCanvas inherits from java.awt.Component, so when you add a GLCanvas to your JFrame, you could use the glasspane on your containing JFrame.

Or, depending on the visual effect you want, you could, after your scene is done rendering on the GLCanvas, add a GL call to glOrtho, and then draw your menu on top of the scene using primitives in GL itself, (though then you'd be stuck rigging your own callback behaviors and such... I'm not sure from the question if you want to get into that).

JPDecker
I don't think I can use the glass pane since the canvas will actually be drawn on top of the glass pane because it's a heavyweight component. And you are correct, I don't really want to start implementing my own callback mechanisms and making direct GL calls.
Jeff Storey
So if you set the swing component to be heavyweight it still doesn't work? Hmm... trying it just now, I've found you can render swing pulldown menus over a glcanvas without problems by doing:JPopupMenu.setDefaultLightWeightPopupEnabled(false);ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);(Though this needs to be done before you do anything with the JFrame)
JPDecker
A: 

Are you talking about a popup menu? You can add a MouseListener to your GLCanvas (since it extends from Component), in the MouseListener, check the mouseEvent.isPopupTrigger(), and if so, create your JPopupMenu - since you want to show it over a heavyweight component, call setLightweightPopupEnabled(false) before showing the JPopupMenu - then call show(glCanvas, x, y) on your JPopupMenu.

Nate
Hi Nate, I'm not talking about a popup menu here. Menu might have been a bad description. It's more of a floating panel. It can be in a fixed location for now. I'm guessing I'll need to use a layout manager that allows me to overlap components and have a Panel (awt) overlapping the GLCanvas.
Jeff Storey