Erro no Jtable

5 respostas
fsf

Oi pessoal,

Aqui estou eu com mais uma duvida no Jtable.

Vamos la, Criei um jtable que esta recebendo dados do bd, mas está acontecendo alguns erros na tela como: O Jtable nao esta aparecendo direito, os botoes da tela so aparecem quando passo o mouse por cima deles, isso tambem acontece com os jlabel.

Vejam o erro que esta dando:

Exception occurred during event dispatching:

java.lang.ArrayIndexOutOfBoundsException: 14 >= 8

at java.util.Vector.elementAt(Unknown Source)

at javax.swing.JTable$1.getValueAt(Unknown Source)

at javax.swing.JTable.getValueAt(Unknown Source)

at javax.swing.JTable.prepareRenderer(Unknown Source)

at javax.swing.JTable.getToolTipText(Unknown Source)

at javax.swing.ToolTipManager.mouseEntered(Unknown Source)

at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)

at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.trackMouseEnterExit(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Alguem pode me ajudar???

5 Respostas

Luiz-SP

São Paulo-SP

Não vi seu código, mas se vc tiver usando esse construtor:
JTable tabela;
        tabela = new JTable(Object[][] rowData, Object[] columnNames);
Certifique-se se vc não estourou os limites dos arrays do construtor, pois a exception que vc lançou é refente a esse tipo de problema.

Luiz Claudio F. dos Santos

marcioa1

Amigo,

Você está usando um model, tipo meuModelo extends AbstractTableModel, e no construtor : new JTable(meuModelo) ???

Tem tutorial sobre isto aqui no GUJ,

Boa sorte

Márcio

fsf

“Luiz-SP”:
São Paulo-SP

Certifique-se se vc não estourou os limites dos arrays do construtor, pois a exception que vc lançou é refente a esse tipo de problema.

Luiz, os arrays estao sem limetes. De uma olhada no codigo!!

Desde ja agradeco!

private DefaultTableModel linha = new DefaultTableModel(); 
 private Vector cabecalho = new Vector (); 
 private Vector linhas = new Vector (); 


    public void preencher(String x){ 
        String escolha = x; 
        
        
        conexao(); 
        //bloco try responsavel por recuperar o codigo da categoria 
        try{ 
            Stmt=con.createStatement(); 
            
            RS= Stmt.executeQuery("Select cod_categoria from Categoria  where nome = '"+escolha+"'"); 
            int i=0; 
            if(RS.next()){ 
                
                cod = RS.getString("cod_categoria"); 
            } 
            
            // JOptionPane.showMessageDialog(null, 
            // cod); 
        }catch(SQLException ex){ 
            JOptionPane.showMessageDialog(null,"Erro ao Recuperar o codigo da categoria!", 
            "Mensagem",JOptionPane.ERROR_MESSAGE); 
        } 
        //bloco try responsavel por recuperar os dados do produto 
        try{ 
            Stmt=con.createStatement(); 
            
            RS= Stmt.executeQuery("Select *  from Produto where cod_categoria = "+Integer.parseInt(cod) ); 

           RS.next(); 
                
            ResultSetMetaData rsmd = RS.getMetaData(); 
             for(int i = 1; i<=rsmd.getColumnCount(); i++) 
            
                  
                 cabecalho.addElement(rsmd.getColumnName(i)); 
          
            
            do{ 

                linhas.addElement(proximaLinha(RS,rsmd)); 
              } 
              while(RS.next()); 
            
           linha = new DefaultTableModel(linhas,cabecalho); 
            
        tabela = new javax.swing.JTable(linha); 
        tabela.setBorder(new javax.swing.border.TitledBorder( 
        new javax.swing.border.EtchedBorder(), "Produtos:", 4, 2, 
        new java.awt.Font ("Dialog", 0, 12), java.awt.Color.black)); 
        



          
          
         JScrollPane barra = new JScrollPane(tabela); 
         barra.setBackground(java.awt.Color.white); 
          
         getContentPane().add(barra); 
         barra.setBounds(50, 90, 480, 140); 



                                                        
        

            
              fechar(); 
        }catch(SQLException ex){ 
            JOptionPane.showMessageDialog(null,"Erro ao Executar a Consulta!", 
            "Mensagem",JOptionPane.ERROR_MESSAGE); 
        } 
              
        
        
    } 
              private Vector proximaLinha(ResultSet RS, ResultSetMetaData rsmd){ 

              Vector LinhaAtual = new Vector();  
              try 
              { 

              for ( int i = 1; i<=rsmd.getColumnCount();i++) 
              
                                          
                   switch(rsmd.getColumnType(i)) 
              { 
               case Types.VARCHAR: LinhaAtual.addElement(RS.getString(i)); 
               break; 
               case Types.TIMESTAMP: LinhaAtual.addElement(RS.getDate(i)); 
               break; 
               case Types.NUMERIC: LinhaAtual.addElement(new Long(RS.getLong(i))); 
               break; 
               } 
               } 
               catch(SQLException e){ 
               e.printStackTrace(); 
                
               } 
               return LinhaAtual; 
               }
fsf

“marcioa1”:
Amigo,

Você está usando um model, tipo meuModelo extends AbstractTableModel, e no construtor : new JTable(meuModelo) ???

Tem tutorial sobre isto aqui no GUJ,

Boa sorte

Márcio

Ja dei uma olhada no tutorial e estou esperando a segunda parte. Estou usando o tablemodel, de uma olhada no codigo acima!!

Desde ja agradeco!!

fsf

Consegui resolver o problema!valeu!!!

Criado 24 de julho de 2004
Ultima resposta 27 de jul. de 2004
Respostas 5
Participantes 3