• Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O with a DefaultTableModel object  RSS feed

 
Nicholas van Orton
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this is an IO issue of a Swing issue (or perhaps a little of both), however I have a data structure as follows and I'm having issues with writing the data with a DefaultTableModel object included:

- Vector, used to store any number of 'batch' objects
- A 'batch' object contains a DefaultTableModel object to display tabular data

The idea behind all of this is to allow for any number of 'batch' objects to contain a DefaultTableModel object and be stored within the Vector (the Vector being the object that is written to and read from file).

Rows, columns and data can be added to the DefaultTableModel object and the Vector object written to and read from file without problem, provided that the DefaultTableModel is not displayed in a JTable object.

Once the Vector has been read and the DefaultTableModel object set to be displayed within a JTable, trouble arises.

i.e.:



Without any changes to the DefaultTableModel object, I go to save the Vector and the following exception occurs (my appologies if this is a little long):



The JTable is being displayed within a JFrame that uses the SpringLayout layout manager.

I am completely lost as to why this is occuring.

Perhaps using a DefaultTableModel object is not the best way of storing tabular data?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An object must implement the java.io.Serializable interface in order to be processed by ObjectIn/OutputStream. Have a look at the javadoc for those classes for the details.
 
Nicholas van Orton
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.swing.SpringLayout does not implement the java.io.Serializable interface, which would explain why Java can't write a SpringLayout object to file. The next question would be why my program would be trying to write a SpringLayout object in the first place.

I've put together a very stripped-down version of what I'm trying to do:





Those two snippets of code work quite well and show that what I'm trying to do is possible.

The hardest part in this post is trying to present what I'm working with in a way where someone might be able to help my with where I am going wrong.

The reading and writing of data is handled here.

This vector is being used to store these objects.

Things seems to go quite well until the DefaultTableModel object is asked to be displayed (here) in a JTable (here).

The code that I have put together are all kept within here.

Any help with this would be very much appreciated, as would an explanation as to why this is happening.

Thanks,
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry but I don't have time to read all your code. Looking at the stack trace it's clear that the exception is thrown when the Vector is getting serialized. Perhaps you could print the contents of the Vector before it is serialized, then work backwards to figure out how a SpringLayout instance is getting placed in it.
 
Nicholas van Orton
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've gone and rebuilt the suspect class, and have found that the following code seemed to have been the problem:



Replacing that section of code with t = new javax.swing.JTable(); has worked.

Overriding the isCellEditable method has had to occur in this class instead, where the DefaultTableModel objects are created:



Any clues as to why this problem has occurred?

Thanks,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!