Swing 组件如何在内部创建、布局、重绘、事件通知……?
我想知道是否有一个很好的文档(或(可查看的)电子书)关于 Swing 组件的生命周期。
无论如何,“生命周期”是正确的术语吗?
我希望找到以下问题的答案:
- 如何、何时、以什么顺序调用绘画方法?
- 如何、何时、由谁调用哪些事件?
- 组件创建的方法调用的确切顺序是什么?
我有时会遇到应用程序的奇怪行为,例如:
- 在 setVisible(true) 之前调用 ComponentListener 的 resize 事件
(因此根窗格具有负尺寸!) - 仅在手动调整 JFrame 大小后,某些组件才能正确布局。
- 将超类从 JPanel 更改为 JLayeredPane 会导致我的类 在其他容器内以不同的方式布局。
- 还有很多其他奇怪的事情...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很久以前也有同样的问题。
我不敢相信在互联网上找到关于这个主题的好资源有多么困难。
幸运的是,我找到了这个链接,现在我将它放在带有金色标签的书签中。 :)
Swing 架构概述
一旦您很好地掌握了如何它们在概念上起作用,您将能够解决您提到的大多数问题。
我希望它有帮助。
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.