Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with getPreferredSize()

Geoffrey Falk
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need some help. I am writing a fractal generator. The main window has a BorderLayout with some controls in the NORTH and SOUTH fields. The CENTER field has a Canvas component with a preferred size.
The problem is, how do I calculate the correct size of the containing Frame? If I call getPreferredSize() on the NORTH and SOUTH components from the Frame constructor, it is returning zero. I think this is because they haven't been initialized ?
More generally, I don't understand the process of initialization of AWT components. Can somebody please explain to me in general how getPreferredSize() works, how it is used by the LayoutManager, etc? Thanks..
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic