tags:

views:

28

answers:

2

Hi, What is the importance of JTable model.Does all the swing components has model associated with it.

+2  A: 

please have a look at MVC design pattern:

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

and yes, most of the java swing components have models, see:

http://java.sun.com/docs/books/tutorial/uiswing/components/model.html

Viele
+4  A: 

Swing uses the Model-View-controller design pattern. As such, most components provided with Swing have indeed an associated model (not all of them, though).

This allows you to separate the rendering part from the data part. I would recommend you to use your own model for JTable, especially if you are manipulating and/or changing data from it.

However, if you don't have such need, and your JTable is only something you use once, in a small corner of your program, with fixed datas, you can also manipulate data directly from the JTable, neglecting the MVC pattern. A JTable created without specifying a model will create its own model, and the JTable class provides methods to manipulate the data directly, for such cases.

Gnoupi
I agree with you, but, in my opinion, the case where you should directly use JTable is only for GUI prototyping.
Sylvain M
@Sylvain - yes, this, or very small programs in which the table is only fed with "manual" datas. Any other case should be using the TableModel.
Gnoupi