Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Funny JFrame behaviour  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!