Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove 1 selected Row from JTable
    text
    copied!<p>I try for almost 2 hours to figure out how to remove and update 1 row from a JTable but somehow it wont work. I use the following code:</p> <pre><code>DefaultTableModel modelTable = (DefaultTableModel) jTabelRooster.getModel(); modelTable.addRow(new Object[]{lid.getLidnummer().toString(), lid.getLidvoornaam(), lid.getLidtussenvoegsel(),lid.getLidachternaam(), lid.getAanwezig()}); </code></pre> <p>Ok so far so good.. rows are nicely added.. but now i would like to remove them:</p> <pre><code>int SelectedRow = jTabelRooster.getSelectedRow(); modelTable.removeRow(SelectedRow); </code></pre> <p>When i do this i get the following error: <strong>Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 >= 2</strong></p> <p>Your help would be appreciated</p> <p>EDIT: the jTabelRooster has been inserterd by the gui layout manager So i have this code now, and i dont get much succes:</p> <pre><code>private void initRoosterDetail() { for(int i = 0; i &lt; leden.size(); i++) { lid = leden.get(i); modelTable.addRow(new Object[]{lid.getLidnummer().toString(), lid.getLidvoornaam(), lid.getLidtussenvoegsel(),lid.getLidachternaam(), lid.getAanwezig()}); } } private void jbInschrijvingVerwijderenActionPerformed(java.awt.event.ActionEvent evt) { int SelectedRow = jTabelRooster.getSelectedRow(); modelTable.removeRow(jTabelRooster.convertRowIndexToModel(SelectedRow)); } </code></pre> <p>this must be it :)</p> <p>When i select 1 row in the table and press the cancelbutton.. i receive this message:</p> <p><strong>Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 >= 2</strong></p> <p><strong>========================================================================================================================================================================================================================================================================================================================================</strong></p> <p>Thanx all for the help... i know what i did wrong... it had to do with a tableModelListener i used.. so this left me with another problem :)</p> <pre><code> jTabelRooster.getModel().addTableModelListener( new TableModelListener() { public void tableChanged(TableModelEvent evt) { if(jTabelRooster.getSelectedColumn() == 4) { } } }); </code></pre> <p>This code was messing the deleterow command.</p> <p>I have 1 boolean column with checkboxes in it :(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload