tags:

views:

54

answers:

4

In a JTextPane what are the MVC components?

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

A: 

You always start with the JavaDocs...

willcodejavaforfood
+1  A: 

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.

Riduidel
A: 

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

VJ
+1  A: 

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.

trashgod