My problem is that I want to save a JTable locally with all it's properties then load it back from a file. I tried serializing, but found out that I can't serialize SpringLayout. I tried to use transient keyword, but it didn't seem to work. After that I tried to use XMLEncoder. Now it gives java.lang.InstantiationException: java.util.Arrays$ArrayList error. I mainly need to save the following: column name, column width, column order, table data How should I do it? Should I just save all of this in a txt file, and parse it later?
Asked
Active
Viewed 107 times
1
-
2Does the spring version of `JTable` use a [`TableModel`](https://docs.oracle.com/en/java/javase/15/docs/api/java.desktop/javax/swing/table/TableModel.html)? It's really the model that makes most sense to serialize and restore, rather than the table itself. – Andrew Thompson Jun 10 '21 at 13:11
-
1I would suggest you need two files for this: 1) to store the model data. See: https://stackoverflow.com/a/30715923/131872. You would need to modify the code to get the data from the JTable (not the TableModel) since the table `getValueAt()` method will get the data in the current column order. 2) for the table properties. For the column width you can use a `Properties` file. – camickr Jun 10 '21 at 13:32
-
Thanks for the answers. Yes it has TableModel. – epithite32 Jun 10 '21 at 16:15
-
They're not answers, but comments (technical point). Now you might either enter your solution as an answer below, or simply delete the question using the links below and to the left of it. (The first is preferred, as people might find it later when searching the same thing.) Tip: Add @camickr (or whoever, the `@` is important) to *notify* the person of a new comment. Glad you found the solution. :) – Andrew Thompson Jun 10 '21 at 21:16