This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes model.removeRow() from JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "model.removeRow() from JTable" Watch "model.removeRow() from JTable" New topic

model.removeRow() from JTable

sri rallapalli
Ranch Hand

Joined: Mar 15, 2005
Posts: 88
Hi All,
I am working on the JTable, and i am able to add, edit, delete rows from the table. But when i delete a table and then click the add, then it is not working, it is throwing ArrayIndexOutofBoundException. What i suspecting is, initially the table built with for example 5 rows, and if i delete one row, now it will become 4, but the table not refreshed with 4 rows, so when clicking the add button, it was trying to fetch 5 records. Please let me know how to rectify this problem. I am new to swings.

thanks in advance,
sri rallapalli
Ranch Hand

Joined: Mar 15, 2005
Posts: 88
I am using DefaultTableModel.
I am using the functions as model.removeRow(), model.addRow().

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10747

Are you sure you are passing the correct value for the row index in model.removeRow(int rowIndex)?

If your model has 5 rows and you want to remove the last row, you should be calling model.removeRow(4) and not model.removeRow(5)

Remember, the index starts with 0.

On the other hand,if you are passing the correct index, then you might want to post the part of your code which does the remove operation here to help identify the problem.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link:
subject: model.removeRow() from JTable
jQuery in Action, 3rd edition