简体   繁体   English

Swing组件如何在内部创建,布局,重新绘制,通知事件,......?

[英]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 . 我想知道是否有关于Swing组件生命周期的良好文档(或(可查看的)电子书)。

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) setVisible(true)之前调用ComponentListener的resize事件
    (so that root pane has negative dimensions!) (以便根窗格具有负尺寸!)
  • Some components are laid out correctly only after resizing the JFrame by hand 只有在手动调整JFrame大小后,才能正确布局某些组件
  • Changing a super class from JPanel to JLayeredPane causes my class to be laid out differently inside an other container. 将超类从JPanel更改为JLayeredPane会导致我的类在其他容器中的布局不同。
  • 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 Swing架构概述

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. 我希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM