简体   繁体   中英

Adding components to a GLCanvas

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?

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM