I'm working with Developing games in java and I've been having problems with removing a panel from being visible. If you have the book then the problem is much like chapter 3 "KeyConfigText.java". If you don't own the book then I'm basically tying to get a JPanel to dissapear after hitting a Button on a JPanel. Now I follow all the code in the book that does this as one of its examples(no exactly but very close). The problem is when setting the JPanel to not be visible it doesn't make it invisible it just freezes the JPanel and when I minimize the JFrame from full screen then maximize it the Panel goes away. So I guess that something is happening when I do that that I need to call on the frame so I don't have to do that to get it to go away. I tried to look up what happens when you minimize JFrames but I didn't find anything, so what is happening that isn't happening when I just have the frame open?
The general rule when adding/removing components to/from an already realizes container is to call revalidate() when adding and additionally repaint() when removing. In case of marking a JPanel invisible with setVisible(false) it may be sufficient to call repaint() on the panel's parent container. Or not, depending on details we still don't know anything about.
There are no new questions, but there may be new answers.
Joined: Sep 05, 2010
Okay well it might take me a couple days to create a short example but for now can someone tell me what methods get called when a JFrame is minimized, because that seems to remove the JPanel properly only when I do that. So I think I need to call one of those methods.
When you minimize a JFrame and then restore it, it's repainted. The question "What methods get called" is unfortunately a naive one, because keeping track of what is supposed to appear when is an extremely complicated process, but Darryl already provided you with the simple answer to what you should probably do.
Although we haven't seen any code, so we can't be sure. It shouldn't take you that long to produce a simple piece of code which just has a JFrame and two JPanels, and subsequently makes one of them invisible.
I've found that making a component invisible automatically causes its parent to be redrawn, which results in that component disappearing and the other components being rearranged inside the parent. But that's my code. Yours apparently does something different.