This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Game Development and the fly likes Painting problems? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Painting problems?" Watch "Painting problems?" New topic
Author

Painting problems?

Alec Porter
Greenhorn

Joined: Sep 05, 2010
Posts: 29
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?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem. Not all your code.

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.

luck, db
There are no new questions, but there may be new answers.
Alec Porter
Greenhorn

Joined: Sep 05, 2010
Posts: 29
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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Painting problems?
 
Similar Threads
Custom Layout Manager
problems in refreshing a Frame window after any event
threads for GUI and command-line
Repaint my swing app
Help sorting out what combination of layouts will provide the result I need