Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes JTable delete row problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable delete row problem" Watch "JTable delete row problem" New topic
Author

JTable delete row problem

Mason Zhao
Greenhorn

Joined: Sep 19, 2007
Posts: 21
Hi, friends,

I have a JScrollPane contains a JTable(DefaultTableModel). When I delete one row of table, like " tableModel.removeRow(index)", the problem occurs, the tableModel removes row(index), but the row (index+1) on the UI disappears. I am so confused, can anybody give me a hand?
Thanks,
Have a great day!

Mason
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
works fine for me, problem must be in your code
Mason Zhao
Greenhorn

Joined: Sep 19, 2007
Posts: 21
Sorry Michael,
I didn't explain clearly. In my JTable every row contains a JPanel, the JPanel contains one label,one editButton, one deleteButton.
when I click on the deleteButton, I want the JTable remove the row(index=JTable.getSelectedRow()) what I clicked, But the results are: the tableModel removes the row(index), the JTable UI removes the row(index+1).

Any suggestion is highly appreciated.

Mason
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Mason Zhao:
In my JTable every row contains a JPanel, the JPanel contains one label,one editButton, one deleteButton.
when I click on the deleteButton, I want the JTable remove the row(index=JTable.getSelectedRow()) what I clicked, But the results are: the tableModel removes the row(index), the JTable UI removes the row(index+1).


How are you removing the row? Are you doing it from within your table model or without? Are you remembering to call fireTableRowsDeleted()?


bitguru blog
Mason Zhao
Greenhorn

Joined: Sep 19, 2007
Posts: 21
I use DefaultTableModel, do i still need fireTableRowdeleted()?

Thank you.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Mason Zhao:
I use DefaultTableModel, do i still need fireTableRowdeleted()?


The fireTableRowsDeleted() has to be called somehow. If you are
using DefaultTableModel.removeRow() then it calls it for you, and
from your original post is appears that's how you are doing it so
you should be ok.

How exactly are you deleting the row? You mention a delete button
in a JPanel in each table row. So you have a custom cell editor
that calls removeRow(), is that it?
Mason Zhao
Greenhorn

Joined: Sep 19, 2007
Posts: 21
Thank you,Brian ,

According to your suggestion, I modified the component renderer and editor, it
really works.

I appreciate your help.

Mason
 
Don't get me started about those stupid light bulbs.
 
subject: JTable delete row problem
 
Similar Threads
JTable
Jtable
JTable
JTable(!!!)
JTable