Exceção para cancelar linhas de uma jTable.  XML
Índice dos Fóruns » Java Básico
Autor Mensagem
petter
Virtual Machine Man

Membro desde: 28/04/2006 17:11:34
Mensagens: 662
Offline

Pessoal fiz um laço for simples para remover todas as linhas da jTable mas lança a exceção:
O meu laço é o seguinte:

Testei e realmente as linhas existem, alguém sabe o porque?

-----------------------------------------
Java is the future
-----------------------------------------
[WWW]
maquiavelbona
JWizard
[Avatar]

Membro desde: 29/06/2006 09:06:51
Mensagens: 2447
Localização: São Paulo - SP
Offline


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.

Até!

----------------------------------------------------------------
"Within a few years a simple and inexpensive device, readily carried about, will enable one to receive on land or sea the principal news, to hear a speech, a lecture, a song or play of a musical instrument, conveyed from any other region of the globe. "
Nikola Tesla - A means for furthering Peace (1905)

"Gedanken ohne Inhalt sind leer, Anschauungen ohne Begriffe sind blind."
Immanuel Kant - Kritik der reinen Vernunft (1781)
Edson Watanabe
Debugger

Membro desde: 05/07/2007 12:38:12
Mensagens: 58
Localização: SP
Offline

Note que à medida que você remove as linhas, o número de linhas diminui. Você pode fazer isto (remover sempre a última linha):

ou então, remover sempre a primeira linha, até acabar a tabela,

maquiavelbona
JWizard
[Avatar]

Membro desde: 29/06/2006 09:06:51
Mensagens: 2447
Localização: São Paulo - SP
Offline

Edson Watanabe wrote:...

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.

Até!

----------------------------------------------------------------
"Within a few years a simple and inexpensive device, readily carried about, will enable one to receive on land or sea the principal news, to hear a speech, a lecture, a song or play of a musical instrument, conveyed from any other region of the globe. "
Nikola Tesla - A means for furthering Peace (1905)

"Gedanken ohne Inhalt sind leer, Anschauungen ohne Begriffe sind blind."
Immanuel Kant - Kritik der reinen Vernunft (1781)
petter
Virtual Machine Man

Membro desde: 28/04/2006 17:11:34
Mensagens: 662
Offline

Pessoal valeu. Agora está funcionando beleza.

-----------------------------------------
Java is the future
-----------------------------------------
[WWW]
davidbuzatto
Moderador
[Avatar]

Membro desde: 07/08/2004 23:47:57
Mensagens: 4013
Localização: Vargem Grande do Sul - SP
Offline


Mais fácil não?

Segundo a documentação...
public void setRowCount( int rowCount )

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.

Seja educado. Agradeça quem te ajudou. Não custa nada.
Dúvidas de Java? Utilize o fórum! Não respondo via MP.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." (Fowler)
"A vida é um escândalo, e no final dá sempre errado. O que humaniza o homem é o fracasso."

http://davidbuzatto.com.br | GitHub | uHunt | CV Lattes | Last.fm
[WWW]
 
Índice dos Fóruns » Java Básico
Ir para:   
Powered by JForum 2.1.8 © JForum Team