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…
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.