tags:

views:

115

answers:

2

I have a JTable and many strings are there in the table. I have selected some particular strings out of those and stored them in an array. At some mouseclicked event I want to display that new array of strings in that table in place of older existing strings.

Actually, I am working on a project in which code is already existing and I am just implementing some features in the already existing table model "Location table mode" assigned to table. Now I have to display new array of strings in this table.

How can I do that? Please help me.

Thanks.

+1  A: 

You need to change the data in the TableModel. One way would be to construct a new DefaultTableModel with your data and set this as the table-model for the JTable using JTable.setModel()

See.... Default Table Model

cagcowboy
A: 

I want to display that new array of strings in that table in place of older existing strings

Do you want to completely erase the JTable's content and use the String Array to fill it up again, or do you want to replace certain Strings from the JTable with the selected ones?

In either case, you will have to make use of the DefaultTableModel which allows you to manipulate the JTable's Data. A useful tutorial for using JTables can be found here How to Use Tables. Basically you would create a new DefaultTableModel from the String Array and use JTableName.setModel(yourNewModel)

or

if you want to replace a Cell's content:

DefaultTableModel model = (DefaultTableModel) JTableName.getModel(); model.setValueAt("a string", row, column);

Tedil