Pessoal fiz um laço for simples para remover todas as linhas da jTable mas lança a exceção:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
O meu laço é o seguinte:
if(modelo.getRowCount() == 4 && contTable == 0){
for(int i = 0; i <= modelo.getRowCount(); i++){
modelo.removeRow(i);
}
}
Testei e realmente as linhas existem, alguém sabe o porque?
for(int i = 0; i <= modelo.getRowCount(); i++){
...
Está aqui o seu erro.
Por exemplo, tens 4 linhas, então os índices vão de 0 a 3. No seu laço, estás percorrendo de 0 a 4, por causa do <=. Tente trocar por < e veja se funciona.
Em seu segundo exemplo, o funcionamento é parecido, mudando só a assinatura do loop. No primeiro não é tão interessante por motivos operacionais mas também tem o mesmo efeito.
Sets the number of rows in the model. If the new size is greater than the current size, new rows are added to the end of the model If the new size is less than the current size, all rows at index rowCount and greater are discarded.[/quote]