aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Lesson: Performing Custom Painting (The Java Tutorials) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Lesson: Performing Custom Painting (The Java Tutorials)" Watch "Lesson: Performing Custom Painting (The Java Tutorials)" New topic
Author

Lesson: Performing Custom Painting (The Java Tutorials)

Mohammed Azeem
Greenhorn

Joined: Aug 17, 2012
Posts: 12
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:

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

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?


luck, db
There are no new questions, but there may be new answers.
Mohammed Azeem
Greenhorn

Joined: Aug 17, 2012
Posts: 12
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

Joined: May 03, 2008
Posts: 4642
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lesson: Performing Custom Painting (The Java Tutorials)