¿Cómo convierto de una base de datos a serialización con listas?

I have this applications where I've used a MySQL server to store and use 5 tables of information. Whenever I had to represent the information - I would use a jTable like this:

# ID Name Info1 Info2 ...
1 231 foo bar troll
2 244 .. .. .. 
3 246 .. .. ..

The ID here is the same primary ID that is stored in the tables. When i wanted the user to select / edit one of these records - I would apply a SelectionListener al jtable, read the ID on the selected row, and apply the changes to that object in the Database (using the ID I read)

Now, I'm trying to convert my application for use with serialized objects and will be storing the state in files. Data will be stored using LinkedList and I will be serializing the lists themselves into files (not individual data entries).

My question is - How do I use LinkedList es jTable such that the user is still able to select / make changes / sort through the jTable.

Para ser más especifico

  1. How do I know which item the user has selected in the jTable - should I use index matching? Or should I insert an ID attribute into the base objects?
  2. How do I perform sorting in the LinkedList on the basis of object attributes (like sort by name, info1, etc.)


preguntado el 09 de enero de 11 a las 04:01

1 Respuestas

You need to create a custom table model. Extend DefaultTableModel and return the data from your LinkedList in your model. You can also implement the setValueAt method to have JTable changes update the LinkedList.

Respondido el 09 de enero de 11 a las 08:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.