java 摆动部件重量轻?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/416947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swing components are light-weight?
提问by arshad
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?
每当我读到 Swing 时,他们都说它们是轻量级组件。所以我只是用谷歌搜索 Swing,发现这意味着 Swing 不依赖于本地同行。这就是为什么它们被称为“轻量级”的原因吗?我的意思是轻量级,我认为 Swing 组件占用的内存比 AWT 组件少。不是这样吗?
回答by coobird
Swingis considered lightweight because it is fully implemented in Java, without calling the native operating system for drawing the graphical user interface components.
Swing被认为是轻量级的,因为它完全用 Java 实现,无需调用本机操作系统来绘制图形用户界面组件。
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.
另一方面,AWT(抽象窗口工具包)是重量级的工具包,因为它只是调用操作系统以生成其 GUI 组件。
The Evolution of the Swing Paint Systemsection from the Painting in AWT and Swingarticle explains the difference between lightweight and heavyweight:
AWT 和 Swing 中的绘画文章中的 Swing Paint System的演变部分解释了轻量级和重量级之间的区别:
When the original AWT API was developed for JDK 1.0, only heavyweight components existed ("heavyweight" means that the component has it's own opaque native window). This allowed the AWT to rely heavily on the paint subsystem in each native platform.
[...]
With the introduction of lightweight components in JDK 1.1 (a "lightweight" component is one that reuses the native window of its closest heavyweight ancestor), the AWT needed to implement the paint processing for lightweight components in the shared Java code.
在为 JDK 1.0 开发原始 AWT API 时,只存在重量级组件(“重量级”意味着组件具有自己的不透明本机窗口)。这允许 AWT 严重依赖每个原生平台中的绘制子系统。
[...]
随着 JDK 1.1 中轻量级组件的引入(“轻量级”组件是重用其最近的重量级祖先的本机窗口的组件),AWT 需要在共享 Java 代码中实现轻量级组件的绘制处理。
As Swing is implemented in Java, it does have some performance disadvantage, however, I hear that performance has improved in recent releases of Java.
由于 Swing 是用 Java 实现的,因此它确实有一些性能劣势,但是,我听说在最近的 Java 版本中性能有所提高。
The advantage of Swing is that it has many more components available such as JTableand JListwhich are more graphical and extensible than the components provided in AWT, allowing for more graphics-rich applications to be developed.
Swing 的优点是它有更多可用的组件,例如JTable和JList比 AWT 中提供的组件更具图形化和可扩展性,允许开发更多图形丰富的应用程序。
回答by cletus
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.
轻量级 vs 重量级是 UI 组件如何实现的问题。重量级组件包装操作系统对象,轻量级组件不包装。它们在 JDK 中严格实现。
回答by Beezer
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).
在这种情况下,Swing 绝对是重量级和复杂的。它被认为不适合瘦客户端实现,并且鉴于今天有这么多不同的设备,Swing 实际上是一种死技术,即使 Oracle 还没有淘汰它...... )。

