How do Swing components implement the MVC architecture?

Suppose I have a JText field. Once this JTextfield implements the MVC architecture?

+3
source share
2 answers

All Java Swing components use MVC, although it is not always clearly visible from the api. For each component there is a controller, model and view. JTextField, JButton, etc. - all controllers. They also support getModel (), which contains the state of the component. Many of the swing APIs pollute the api controller with convience methods, so this is not always obvious. The text displayed in the JTextField is actually stored in the model. textField.getText () and textField.setText () actually exist for your convienence, what they really do is textField.getModel (). getText () and textField.getModel (). setText ().

For representation there is UI getComponentUI (). This is updated using the Changes property released from the model. ComponentUI is what makes it easy to develop L & Fs.

+4
source

A document is a model.

In addition, JTextField implements MVC just like any other Swing component.

+3
source

All Articles