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 Swing / AWT / SWT and the fly likes Funny JFrame behaviour 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 » Swing / AWT / SWT
Bookmark "Funny JFrame behaviour" Watch "Funny JFrame behaviour" New topic

Funny JFrame behaviour

Steffen Reinhard

Joined: Jun 13, 2005
Posts: 19
Hi everybody!

I wrote some code overwriting JPanel's paintComponent() method and put it in a convenience JFrame.

When I run it the Rectangle drawn in paintComponent() is sometimes shown and sometimes it isn't. If it isn't I have to force a repaint by changing JFrame's size and then it is shown ... bizarre! Any Ideas, anybody?

Thanks in advance for any hint on how to solve this problem.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
When you add a component to a container after it (s top-level container) has been realized
you have to let it know so it can do a new layout. We usually do this with the Container
method validate or the JComponent method revalidate. Sometimes you may need
to follow this (validation) with a call to repaint, but not always.
It is sorta covered in the JavaRanch Style Guide.
subject: Funny JFrame behaviour
Similar Threads
AffineTransform "transform" method
AffineTransform Rectangle2D
Problem displaying panel in an applet
Drop Down Menu Buttons