Partage
  • Partager sur Facebook
  • Partager sur Twitter

jTable : ajouter une ligne

java.lang.ClassCastException

Sujet résolu
    28 janvier 2009 à 10:19:55

    bonjour,
    je sollicite votre aide pour un problème qui m'a rendu follllle voila:
    j'ai un bouton qui m'aide à ajouter des row dans une jtable
    DefaultTableModel model = (DefaultTableModel) tablListe.getModel();
    						model.addRow(new Object[]{""+txtCodPos.getText(),""+labNatPos.getText(),""+labNatPos.getText(),""+labNatPos.getText()});
    						tablListe.updateUI();
    


    normalement ca doit marcher mais il me donne une exception voila:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JTable$1
    	at ma.transparence.FrmCirProd$11.actionPerformed(FrmCirProd.java:946)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.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.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.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    


    comme si il me dit qu'il est impossible de caster jtable vers defaulttablemodel :colere2: pourtant j'ai googler et googler et je trouve toujours la même méthode
    svp aidez moi :(
    • Partager sur Facebook
    • Partager sur Twitter
    Anonyme
      30 janvier 2009 à 5:35:25

      Salut,
      oui la cause de cette exception c'est le fait que la méthode getModel() retourne un TableModel et non un DefaultTableModel. L'interface TableModel, lui il ne défini aucune méthode qui te permet d'ajouter des lignes( resp. colonnes ).
      Donc je pense que tu devras créer ta propre méthode TableModel :-° .
      • Partager sur Facebook
      • Partager sur Twitter

      jTable : ajouter une ligne

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown