Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JMenu displaying underneath JPanel when clicked

843807Jun 25 2010 — edited Jun 28 2010
Hi there.

I've been writing a Java implementation of Conway's Game of Life to flex my GUI muscles and stay in shape. It consists of a class extending JPanel in which all of the drawing is done, and a main class where the panel is created and a JFrame is set up, and so on.

My JFrame has a JMenuBar with one JMenu, called "Simulation". Inside the Simulation menu there are two JMenuItems: "New Simulation..." and "Reset Simulation".

The problem I am having is that whenever I click the Simulation menu, it opens for a brief moment and I see the two menu items, but then it is painted over by the panel as soon as the next repaint happens.

I have investigated the setComponentZOrder method, and tried several permutations of the following code, to no avail.
frame.getContentPane().setComponentZOrder(menuBar, 0);
frame.getContentPane().setComponentZOrder(panel, 1);
How can I prevent my JPanel from painting over my expanded JMenu?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2010
Added on Jun 25 2010
8 comments
563 views