Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1211

JTable calls setValueAt w

From "Lionel van den Berg" <lionel.van.den.berg@THRWHITE.remove-dii-this>
Subject JTable calls setValueAt w
Message-ID <45fd081e$1@dnews.tpgi.com.au> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:32 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
I'll start with minimal information in case this has a simple solution

I've got a JTable, table, and I've sub-classed AbstractTableModel and 
set the JTable model to an instance of my sub-class. My model just has 
an ArrayList, dataList, that holds the data types that represent each 
row. My getRowCount() method in my model simply returns dataList.size().

I've got a delete button that calls: 
((AbstractTableModel)table.getModel()).deleteRow(table.getSelectedRow());

The deleteRow(int row) method simply does:
dataList.remove(row);
fireTableRowsDeleted(row, row);

If I have a table with two entries, select the last entry and press 
delete once it deletes the entry and there are no rows selected after it 
is removed. If I press delete again my application catches this saying 
that there is nothing selected (getSelectedRow() returns -1) but after 
JTable seems to call model.setValueAt(...) with a row index of 1 which 
is out of bounds. Of course this causes an IndexOutOfBoundsException 
when it happens.

Why is this method being called with this illegal value? The only 
solution I've found is to call:

table.setEditingRow(Table.getRowCount() -1);

But I don't like this, it seems like a hack.

Any ideas?

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar | Unroll thread


Thread

JTable calls setValueAt w "Lionel van den Berg" <lionel.van.den.berg@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
  Re: JTable calls setValue "Michael Rauscher" <michael.rauscher@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
    Re: JTable calls setValue "Lionel van den Berg" <lionel.van.den.berg@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000

csiph-web