• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable delete row problem

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
works fine for me, problem must be in your code
 
Mason Zhao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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()?
 
Mason Zhao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use DefaultTableModel, do i still need fireTableRowdeleted()?

Thank you.
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you,Brian ,

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

I appreciate your help.

Mason
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic