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


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

JTable calls setValueAt w

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail
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)
X-Comment-To comp.lang.java.gui
Newsgroups comp.lang.java.gui
Content-Type text/plain; charset=IBM437
Content-Transfer-Encoding 8bit
X-Gateway time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92]
Lines 36
Date Wed, 27 Apr 2011 15:32:00 GMT
NNTP-Posting-Host 96.60.20.240
X-Complaints-To news@tds.net
X-Trace newsreading01.news.tds.net 1303918320 96.60.20.240 (Wed, 27 Apr 2011 10:32:00 CDT)
NNTP-Posting-Date Wed, 27 Apr 2011 10:32:00 CDT
Organization TDS.net
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.gui:1211

Show key headers only | 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