Swing 组件重量轻吗?

发布于 2024-07-10 20:41:46 字数 166 浏览 3 评论 0原文

每当我读到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

此岸叶落 2024-07-17 20:41:46

Swing 被认为是轻量级的,因为它完全用 Java 实现,无需调用本机用于绘制图形用户界面组件的操作系统。

另一方面,AWT(抽象窗口工具包)是重量级工具包,因为它仅调用操作系统以生成其 GUI 组件。

Swing Paint 系统的演变 部分来自 Painting in AWT and Swing 一文解释了轻量级和重量级之间的区别:

最初的 AWT API 是什么时候
仅针对 JDK 1.0 开发
重量级组件已经存在
(“重量级”意味着
组件有它自己的不透明本机
窗户)。 这使得 AWT 能够依赖
严重依赖于每个中的绘画子系统
原生平台。

[...]


轻量化的引入
JDK 1.1 中的组件(“轻量级”
组件是一个重用的组件
最接近的本机窗口
重量级祖先),需要 AWT
实施油漆加工
共享中的轻量级组件
Java 代码。

由于 Swing 是用 Java 实现的,因此它确实有一些性能缺点,但是,我听说最近发布的 Java 版本中性能有所提高。

Swing 的优点是它有更多可用的组件,例如 JTableJList 比 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:

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.

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 and JList which are more graphical and extensible than the components provided in AWT, allowing for more graphics-rich applications to be developed.

疾风者 2024-07-17 20:41:46

轻量级 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.

迟月 2024-07-17 20:41:46

这只是一个附录,在另一个上下文中解决重量级与轻量级:编程模型。

在这种情况下,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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文