简体   繁体   中英

Removing a JPanel from a JFrame

I am currently working on an intro screen for a game designed using JOGL. I want the intro to be a JPanel with a few buttons to alter options before starting the game.

So, I have JFrame which I add a GLCanvas to. The GLCanvas also contains a GLEventListener. Finally, I add the JPanel.

I have overridden the JPanel paintComponent method to set a background image. I have a few buttons within the panel. Whenever you click the 'play' button, it calls a function which does:

frame.remove(JPanel); frame.repaint(); animator.start();

What happens is that my JPanel goes away correctly, but when repaint is called, my frame is just filled with grey. I know that the animator is starting correctly as the display method in my GLEventListener is getting called.

Does anyone know what the problem is there?

What is your LayoutManager? If you didn't specify one, then by adding the JPanel you replace the GLCanvas.

I would make your code do this:
frame.remove(JPanel); frame.add(glcanvas); animator.start();
you may need to throw in a frame.revalidate(). I'm not up on how all that works right now.

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