| Autor |
Mensagem |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 06/07/2007 17:40:01
|
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
----------------------------------------- |
|
|
 |
|
|
![[Post New]](/templates/default/images/icon_minipost_new.gif) 06/07/2007 17:44:43
|
maquiavelbona
JWizard
![[Avatar]](/images/avatar/24bea84d52e6a1f8025e313c2ffff50a.jpg)
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) |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 06/07/2007 17:49:35
|
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,
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 06/07/2007 17:53:10
|
maquiavelbona
JWizard
![[Avatar]](/images/avatar/24bea84d52e6a1f8025e313c2ffff50a.jpg)
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) |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 06/07/2007 18:47:32
|
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
----------------------------------------- |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 07/07/2007 01:46:01
|
davidbuzatto
Moderador
![[Avatar]](/images/avatar/7ba6d33c373fea56b7258003b16c68e5.jpg)
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 |
|
|
 |
|
|