• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Lesson: Performing Custom Painting (The Java Tutorials)

 
Ranch Hand
Posts: 64
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I'm studying the Lesson on Performing Custom Painting in the Java Tutorials. The lesson is in three steps.

In step 2, a JFrame named f is created. A JPanel object called MyPanel is also created and then added to the frame f.

A method named getPreferredSize is defined to set MyPanel's size but the problem I have with understanding why this method is never invoked anywhere in the code. So how does MyPanel and ultimately the JFrame to which it is attached get their sizes.

I am always impressed by the insights offered in this forum, thank you for you help.

The code listed below:

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mohammed Azeem wrote:A method named getPreferredSize is defined to set MyPanel's size but the problem I have with understanding why this method is never invoked anywhere in the code. So how does MyPanel and ultimately the JFrame to which it is attached get their sizes.


This recent thread may be of interest: When is the preferredSize() method of the Container class called?
 
Mohammed Azeem
Ranch Hand
Posts: 64
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Darryl.

Just to clarify my further reading around this issue: am I correct in thinking that pack() calls the getPreferredSize method automatically in this example?

Thanks.

 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing automatic about it. If you really want to know what goes on under the hood, study the JDK source code which you can find in src.zip in your JDK install directory.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!