0

How do you change data in jtable in java

I have a joptionpane that takes input and puts it into my jtable (I'm using a Object[][] for the array and abstract table model). I want to know how to erase all the data in the table and insert new data. So for example I would enter in a few strings into the jtable then I want to say click a button and have all the data in the table be removed and be able to add new strings from the first row and so on.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
PeteGuru
  • 1
  • 1
  • possible duplicate of [How to clear contents of a jTable ?](http://stackoverflow.com/questions/3879610/how-to-clear-contents-of-a-jtable) – Tony BenBrahim Aug 08 '14 at 06:08

1 Answers1

1

Create a new TableModel and apply it to the JTable using JTable#setModel

For example...

table.setModel(new DefaultTableModel(columns, 0));
// Columns is an array of column names you have previously 
// specified...

See How to Use Tables for more details...

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366