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
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
jTable such that the user is still able to select / make changes / sort through the
Para ser más especifico
- 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?
- How do I perform sorting in the
LinkedListon the basis of object attributes (like sort by name, info1, etc.)
preguntado el 09 de enero de 11 a las 04:01
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.