GLCanvas and JMenuBar

Hi,

I have attempted to add a JMenuBar to my JFrame which contain items like File, Save, Exit etc. However when I click on a menu item its drop down list does not appear - this is because I have a lightweight component attempting to display over a GLCanvas which is a heavyweight component.

Does anybody know how I could get round this problem?

Regards,

Sally

Hi,

JPopupMenu.setDefaultLightWeightPopupEnabled( false ); should work.

Yes, that does work, miraculously! :slight_smile: However, have now noticed that clicking on a menu item causes an unwanted call to display() method. ??? I suppose there’s no way of stopping it doing that, but I guess it’s not a huge problem anyway.

Thanks for your reply though.

Sal.

The call to display is caused because part of the window is overwritten, I believe there is a way to turn that off. I believe Frame.setIgnoreRepaint(true) will do it.

Oh nice one. And there was me thinking that it wouldn’t have been possible. Just shows what you get by asking.

Thanks,

Sal.

Good to here it works (uh, it does right?). Sometimes I ask questions and feel stupid once I get the answer and see it was pretty much in plain sight in the API documentation… but other times the answers are pretty well hidden, I only knew of this little trick because it is mentioned in sun’s tutorial on using the fullscreen api.

Hi Dank,

Yes it did work, but I removed the line because a permanent grey rectangle was left from where the menu had dropped down and overpainted the GLCanvas. This is because the rendering of the GLCanvas is done directly in video memory so it is impossible to draw a popup menu over a GLCanvas without overwriting the FrameBuffer. So it still calls display() and I still have a problem.

I think the only way for me to do it - it’s terribly clumbsy and might not even work (but if anybody has any better ideas I’m all ears) is to use a boolean variable which I set to true on mousereleased event for menu items. It then copies the whole pixel data of the glcanvas into memory - the display() event sees that the boolean variable is set to true and hence does not do its normal rendering but copies all the pixel data back to the glcanvas in all its original glory.

Regards,

Sal.

Why not use a standard AWT menuBar? It works fine for me.