Removing JPanel from JFrame

I am currently working on an intro screen for a game developed using JOGL. I want the introduction to be a JPanel with a few buttons to change parameters before starting the game.

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

I have overridden JPanel's paintComponent method to set the background image. I have several buttons inside the panel. Whenever you press the play button, it calls a function that does the following:

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 gray. I know that the animator starts correctly when the display method in my GLEventListener is called.

Does anyone know what the problem is?

0


source to share


1 answer


What's your LayoutManager? If you didn't specify one, then adding a JPanel will replace the GLCanvas.



I would do your code: frame.remove (JPanel); frame.add (glcanvas); animator.start ();
you may need to insert frame.revalidate (). I don't understand how this all works right now.

+2


source







All Articles