views:

129

answers:

4

Hello!

I wonder if there's a good documentation (or a (viewable) ebook) about the lifecycle of Swing components.

Is "lifecycle" the correct term, anyway?

I hope to find answers to question such as:

  • How, when, in which order painting methods are called?
  • How, when, which events are called by whom?
  • What is the exact sequence of method calls for component creation?

From time to time I encounter strange behavior of my apps, for example:

  • ComponentListener's resize event is called before setVisible(true)
    (so that root pane has negative dimensions!)
  • Some components are laid out correctly only after resizing the JFrame by hand
  • Changing a super class from JPanel to JLayeredPane causes my class to be laid out differently inside an other container.
  • And lot of other strange things...
A: 

I've had good experiences with the O'Reilly Swing book; if you want, you can use the free trial of the Safari Books Online to get access to the whole book.

McWafflestix
+1  A: 

I had the same question long ago.

I can't believe how hard is to find a good resource about this topic in the internet.

Fortunately I've found this link and now I have it in my bookmark with golden tag. :)

A Swing Architecture Overview

Once you have a good grasp of how they work conceptually you will be able to fix most of the problems you mention.

I hope it helps.

OscarRyz
A: 

FilthyRichClients is a good resource to understand some of the concepts above, especially chapter two which covers:

  • Swing Rendering Fundamentals
  • Events
  • Swing Painting
  • Swing Rendering
  • Double-Buffering
  • Threading

The website is here:

http://filthyrichclients.org/

and you can get the book on Amazon or O-Reilly Safari also...

Jon
A: 

The best source of documentation for Swing is the source code (src.zip in your JDK). Unfortunately you really need to look into it to understand what it's up to.

Tom Hawtin - tackline
The source code is much easier to read and understand once you've got the high level view.
OscarRyz
Looking at the questions in the question, looking at the source seems an ideal way to go.
Tom Hawtin - tackline
The source is NOT it's specification. Can't always rely on inter-version consistency by just looking at the source.
ivan_ivanovich_ivanoff
Where is the specification?
Tom Hawtin - tackline