Swing MVC JTextPane 以及其他人通常使用的

发布于 2024-09-10 04:00:30 字数 102 浏览 3 评论 0原文

JTextPane 中,MVC 组件是什么?

另外,如果我想知道 JComponent 的 MVC 部分如何发现它们?

In a JTextPane what are the MVC components?

Also if I wanted to know for a JComponent their MVC parts how can discovery them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

半世晨晓 2024-09-17 04:00:30

在Swing中,MVC的组织是递归完成的。

乍一看,可以考虑每个 JComponent 是呈现关联模型的视图。对于 JTextPane ,关联的模型由getStyledDocument() 方法:文档由 JTextPane 更新,控制层由各种 Swing 监听器提供,它允许您与模型和视图交互。

然而,在另一个层面上,还有另一个 MVC,其中 JComponent 成为模型:它是 LnF。事实上,在这一层中,JComponent 使用 ComponentRenderer 进行渲染,其中侦听器通过模型更新触发视图重绘。但这些配置对“基本”Swing 代码几乎不感兴趣。

考虑到MVC对应的发现,我对这个问题有点困惑。

事实上,据我所知,如果 JComponent 知道其关联模型,那么除了调用其侦听方法(由其 *Listener 接口定义)之外,它一定不了解其侦听器。

此外,developer.com 有 一篇关于 Swing/MVC 主题的文章

In Swing, MVC organization is recursively done.

At first glance, one can consider each JComponent is a view rendering an associated model. In the case of the JTextPane, the associated model is given by the getStyledDocument() method : the document is updated by the JTextPane, and the control layer is provided by the various Swing listeners, which allow you to interact with both model and view.

However, at another level, there is another MVC where the JComponent becomes the model : it's the LnF. Indeed, in this layer, the JComponent is rendered using a ComponentRenderer, where listeners triggers view repaint from model update. But these configuration are almost of no interest in "basic" Swing code.

Considering MVC counterpart discovery, I'm a little puzzled by this question.

Indeed, as far as I know, if the JComponent knows its associated model, it must have no knowledge of its listeners other than the ability to call their listening methods (defined by their *Listener interface).

Besides, developer.com has an article on the Swing/MVC subject.

忘羡 2024-09-17 04:00:30

正如Swing 架构概述,Swing 使用 MVC 的一种变体,称为可分离模型架构,它结合了视图和控制器。在该范例中,JTextPane 模型由 Document 接口,而视图由 JTextPane 本身定义。其他 JComponent 模型在本文的 中列出表

有关 Swing 和 Swing 的更多信息,请参阅MVC 设计,请参阅使用 MVC 进行 Java SE 应用程序设计

As discussed in A Swing Architecture Overview, Swing uses a variant of MVC called separable model architecture, which combines the view and controller. In that paradigm, the JTextPane model is defined by the Document interface, while the view is defined by JTextPane itself. Other JComponent models are listed in the article's table.

For more on Swing & MVC design, see Java SE Application Design With MVC.

浅沫记忆 2024-09-17 04:00:30

您始终从 JavaDocs 开始...

You always start with the JavaDocs...

忆梦 2024-09-17 04:00:30

这是一个很好的页面,显示了 Swing 类层次结构。以及

这篇文章(以及嵌入图像)是 Swing MVC 架构开始的好地方

希望一些这有帮助..

This is a good page showing Swing class hierarchy..

And this article (along with embedded image) is good place to start of Swing MVC Architecture

Hope some of this helps..

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