• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to delete row from Jtable  RSS feed

 
RaviSingh Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used a Jtable to store data fetching from database.
But when i click Delete button to delete some particular row,the selected row get's deleted from database,but it is not refreshed in jtable.
To get it reflected i have to again run the program.

please help me regarding this.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your TableModel implementation you are using? Because you have to delete it from this one as well.

DefaultTableModel has a removeRow(int) method which can remove a row based on the number. For other implementations you have to check yourself. Keep in mind that some TableModels don't allow deletion and refreshing is the only way to go. Either that or change the model.
 
RaviSingh Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But defaulttabelmodel is used with vector for data and column.
And i am using two dimensional array.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But internally DefaultTableModel stores everything inside Vectors.

Here's some of its code:

As you can see, both the data and column names are converted to Vectors.
 
Kelahcim Kela
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by RaviSingh Kumar:
But defaulttabelmodel is used with vector for data and column.
And i am using two dimensional array.


If you are using two dimensional array you have to create new table and rearrange the data (copy all the data that you need after element at specified index is removed). After table is changed you should call

fireTableDataChanged()

method, which will inform all the observers that data inside model have changed.

It would be easier for you to use Vector or ArrayList to store internal data of TableModel.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!