简体   繁体   English

将组件添加到GLCanvas

[英]Adding components to a GLCanvas

I'm working with an application that draws on a GLCanvas. 我正在使用在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). 我想在其顶部添加一个“浮动菜单”(通过在玻璃窗格中添加菜单,我可以在Swing中执行此操作)。 Since GLCanvas doesn't extend Container, what would be the suggested way to do this? 由于GLCanvas不会扩展Container,因此建议的方法是什么?

GLCanvas inherits from java.awt.Component , so when you add a GLCanvas to your JFrame, you could use the glasspane on your containing JFrame. GLCanvas继承自java.awt.Component ,因此,当将GLCanvas添加到JFrame时,可以在包含的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). 或者,这取决于你想要的视觉效果,你可以,你的场景进行渲染的GLCanvas中后,加入GL调用glOrtho,然后绘制在菜单上使用原语GL本身场景的顶部,(虽然那你会陷于操纵自己的回调行为之类的问题……从问题上我不确定您是否想要了解这一点)。

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. 您可以将MouseListener添加到GLCanvas中(因为它是从Component扩展而来的),请在MouseListener中检查mouseEvent.isPopupTrigger(),如果需要,请创建JPopupMenu-因为要在重量级组件上显示它,请调用setLightweightPopupEnabled( false),然后再显示JPopupMenu-然后在JPopupMenu上调用show(glCanvas,x,y)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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