AWTPanel drawing over Swing elements

I have an AWTPanel that likes the draw itself over a menu from a JMenuBar, causing some of the menu to be invisible. It does not do this all the time, and I’m only beginning to understand the rules. It seems to start drawing over the menu when the scene changes, but interacting with some Swing elements will bring the menu back to the top. For example, resizing the frame will fix the problem, but updating a mesh in the scene will bring the problem back.

I have tried to create a small example to illustrate the problem, but I can’t replicate it. I suspect it may be a thread-related problem since I am juggling the Swing event thread and the jME3 main thread, so I have been building in checks to ensure that each method is running on the proper threads. So far I have shuffled certain things from one thread to another and had no apparent effect on the issue. Perhaps it is not related to threads.

I am suspicious of PaintMode. I am creating my AWTPanel with createPanel(PaintMode.Accelerated) because I saw that in an example, but I’ve never found any explanation for the various mode options. I have tried the other two options (Repaint and OnRequest) and neither one fixed the problem, but Repaint did cause the panel to flicker badly and OnRequest stopped updating the scene. Could this be related to the issue?

Since I can’t pinpoint the cause, I can only hope that someone has seen this sort of thing before and knows what sort of issue causes it. I really need some hints about how to track down the cause.

Hi Boko,
yes, the AWTPanel has priority over the Swing elements.

A workaround is the following (this is how the SDK solves the issue):
Do NOT use the AWTPanel!
Instead, render the scene into an offscreen buffer, convert it into an AWTImage and draw it normally in a Swing Panel.
For the details, have a look at the SDK sourcecode, especially com.jme3.gde.core.scene.OffScreenPanel, com.jme3.gde.core.scene.SceneApplication and com.jme3.gde.core.sceneviewer.SceneViewerTopComponent.

Screen shot?

Have you disabled lightweight popups?

JPopupMenu.setDefaultLightWeightPopupEnabled(false);

1 Like

It’s confusing that the AWTPanel doesn’t always draw over the Swing elements, only sometimes. Even when I was deliberately trying to make it happen I would not happen for me. It is a big relief to hear that I’m not causing this; it’s just something that happens.

I’ve tried to make a screen shot, but I can’t figure out what to show. The problem is a menu that is covered by a AwtPanel, so the problem looks exactly like nothing. It’s just a menu that’s not drawn, or drawn and then overdrawn. Either way it’s not very visually distinctive.

If it is important I can try moving things around so that the AwtPanel cuts the menu in half vertically so we see half of each menu item. That would be a striking image.

I’m using a JMenuBar, not a JPopupMenu. Unfortunately that option doesn’t seem to exist for JMenuBar or JMenu.

Is it the menu bar itself that is being clipped or the popup menus when you click on one of the main menu bar buttons? (Because those are JPopupMenus…)

1 Like

I see you are right, of course. The JPopupMenu is created automatically by the JMenu. I was misled since I wasn’t creating any JPopupMenu myself, but I see that you can access the JPopupMenu through a JMenu method.

And as simply as calling setDefaultLightWeightPopupEnabled(false), the problem has disappeared. That is a much easier solution than implementing a substitute for AwtPanel! Thank you very much.

Great.

And I learned something new :slight_smile: