Swing 组件重量轻吗?
每当我读到 Swing 时,他们都说它们是轻量级组件。 所以我用 google 搜索了 Swing,发现这意味着 Swing 不依赖于本地对等体。 这就是它们被称为“轻量级”的原因吗? 我所说的轻量级是指我认为 Swing 组件占用的内存可能比 AWT 组件少。 不是这样吗?
Whenever I read about Swing they say they are light weight components. So I just googled Swing and found that it means Swing does not depend on native peers. Is that why they are called "light weight"? I mean by light weight I thought maybe the Swing components occupy less memory than the AWT components. Isn't that so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Swing 被认为是轻量级的,因为它完全用 Java 实现,无需调用本机用于绘制图形用户界面组件的操作系统。
另一方面,AWT(抽象窗口工具包)是重量级工具包,因为它仅调用操作系统以生成其 GUI 组件。
Swing Paint 系统的演变 部分来自 Painting in AWT and Swing 一文解释了轻量级和重量级之间的区别:
由于 Swing 是用 Java 实现的,因此它确实有一些性能缺点,但是,我听说最近发布的 Java 版本中性能有所提高。
Swing 的优点是它有更多可用的组件,例如
JTable
和JList
比 AWT 中提供的组件更具图形化和可扩展性,允许开发更多图形丰富的应用程序。Swing is considered lightweight because it is fully implemented in Java, without calling the native operating system for drawing the graphical user interface components.
On the other hand, AWT (Abstract Window Toolkit) is heavyweight toolkit, as it merely makes calls to the operating system in order to produce its GUI components.
The Evolution of the Swing Paint System section from the Painting in AWT and Swing article explains the difference between lightweight and heavyweight:
As Swing is implemented in Java, it does have some performance disadvantage, however, I hear that performance has improved in recent releases of Java.
The advantage of Swing is that it has many more components available such as
JTable
andJList
which are more graphical and extensible than the components provided in AWT, allowing for more graphics-rich applications to be developed.轻量级 vs 重量级是 UI 组件如何实现的问题。 重量级组件包装操作系统对象,而轻量级组件则不然。 它们在 JDK 中严格实现。
Lightweight vs heavyweight is a question of how the UI components are implemented. Heavyweight components wrap operating system objects, lightweight components don't. They are implemented strictly in the JDK.
这只是一个附录,在另一个上下文中解决重量级与轻量级:编程模型。
在这种情况下,Swing 绝对是重量级且复杂的。
它不被认为适合瘦客户端实现,并且考虑到当今有如此多不同的设备,Swing 实际上是一种已死的技术,尽管 Oracle 尚未淘汰它……(另请参阅 JavaFX 作为替代方案) )。
This is simply an addendum that addresses the heavyweight vs. lightweight in another context: programming model.
In this context Swing is definitely heavyweight and complicated.
It is not considered suitable for thin client implementation, and given the fact that today there are so many different devices, Swing is, in effect, dead technology, even though Oracle has not retired it...yet (also see JavaFX as an alternative).