Rehan
Rehan

Reputation: 195

Removing displayed data from JTable

This is what 'new' button does in my entry form, in addition to this, i want it to remove all displayed data from JTable. How can i do that?

   saved = false;
   txt_ipath.setText(null);
   txt_md_by_p.setText(null);
   txt_model_p.setText(null);
   txt_p_date.setText(sdf.format(date));
   txt_p_price.setText(null);
   txt_p_qty.setText(null);
   txt_s_price_p.setText(null);
   txt_vouchdate_p.setText(sdf.format(date));
   txt_vouchno_p.setText(null);

Upvotes: 1

Views: 46

Answers (1)

camickr
camickr

Reputation: 324118

Assuming you are using a DefaultTableModel for your JTable you can just use:

model.setRowCount(0);

Or, if you are removing a row of data you can use:

model.removeRow(...);

any changes to the data should be done via the model.

Upvotes: 2

Related Questions