Swing MVC JTextPane 以及其他人通常使用的
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在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.
正如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 theDocument
interface, while the view is defined byJTextPane
itself. OtherJComponent
models are listed in the article's table.For more on Swing & MVC design, see Java SE Application Design With MVC.
您始终从 JavaDocs 开始...
You always start with the JavaDocs...
这是一个很好的页面,显示了 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..