File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Customized Data model help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Customized Data model help needed" Watch "Customized Data model help needed" New topic

Customized Data model help needed

Ajit Malleri

Joined: Feb 10, 2002
Posts: 27
The scenario is that I have a swing frontend which listens to messages from the servlet. What I need to do is to display the data in the swing frontend as and when the data changes. I had seen a posting in some site suggesting setting up a data model which will hold the data. This model could fire events to indicate the changes occuring. All the gui screens would register as listeners to this data model and update themselves as and when the changes take place.
In my swing frontend, I have 3 JTable and one JTree. I want all the data to be updated.
Can someone throw some light on this issue and show examples on how to:
(1) create a data model
(2) fire events to indicate changes
(3) register the screens to the data model
Any help would be highly appreciable.
[ December 08, 2002: Message edited by: Ajit Malleri ]
[ December 08, 2002: Message edited by: Ajit Malleri ]

Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
(1) and (2) The data model should have get and set methods to change the data, and methods (protected) to fire events.

for more information on the event pattern, see:
If you have several tables and a tree, I'd suggest you create one "main" data model that holds your data and that you give as argument to the TableModel and TreeModel implementations (inherit at least from AbstractTableModel and AbstractTreeModel, they implement the event generating methods). These will delegate data requests to the main model and provide view specific implementations such as getColumnName(int col) etc. See the swing tutorial on table and tree models.
(3) These tree and table models should be handled to the view classes that can register listeners on them. JTable and JTree do that automatically, anyway. If you implemented all the methods in the table and tree models well, you shouldn't need to change the JTable and JTree implementations. They will reflect all changes in the data models by themselves. Of course, you can register listeners to make other changes to your interface (change frame titles, menu bars, button states etc.).
[ December 10, 2002: Message edited by: Chantal Ackermann ]
[ December 10, 2002: Message edited by: Chantal Ackermann ]
I agree. Here's the link:
subject: Customized Data model help needed
It's not a secret anymore!