Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are Swing components internally created, laid out, repainted, notified of events, ...?

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...
like image 241
ivan_ivanovich_ivanoff Avatar asked Nov 05 '22 21:11

ivan_ivanovich_ivanoff


1 Answers

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.

like image 122
OscarRyz Avatar answered Nov 12 '22 14:11

OscarRyz