• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Lesson: Performing Custom Painting (The Java Tutorials)

 
Ranch Hand
Posts: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic