This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how to delete row from Jtable

 
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.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic