tags:

views:

17

answers:

1

how can you parse all the data from table model, so that it can readily be loaded and displayed easily as JTable ?

for example, with the loaded JTable, I drag and drop the columns to change the orders. How would I get all of the table information ? Is there a certain standard to store this data in so it can easily be read by the next JTable ?

A: 

Dragging of columns is supported automatically. However, this does NOT change the order of the data in the TableModel and should not do so.

If you want to access the data in the model in the order in which the model was created then you use:

table.getModel().getValueAt(...);

If you want to access the data in the current view of the table then you use:

table.getValueAt(...);

If for some reason you need to convert indexes between the view/model then you can use one of the convertXXX(...) methods found in the JTable API.

Additionally, how can you parse all the data from table model, so that it can readily be loaded and displayed easily as JTable ?

This doesn't make any sense. If the data is already in the TableModel then there is no need to parse it. If you are talking about saving the data to a file, then many people use a simple format like:

data1|data2|data3

Then when you read the data in line by line you can use the String.split(...) method to get each individual method. Then you can use the DefaultTableModel.addRow(...) method to add each row to the model.

camickr