• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Painting problems?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Alec Porter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic