开发者

Swing MVC JTextPane and in generally for others

In a JTextPane what are the MVC components?

Also if I wanted to know for a JComponent their MVC parts how can disco开发者_如何学运维very them?


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.


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.


You always start with the JavaDocs...


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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜