Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1721 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  afficher le contenue d'un tableau dans une interface graphique

 

Sujet(s) à lire :
    - Visual C++
 

 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

afficher le contenue d'un tableau dans une interface graphique

n°2211645
manel1989
Posté le 26-11-2013 à 03:56:09  profilanswer
 

Salut tout le monde!
 
dans mon code il me lorsque je clique sur le bouton "Show Results" il m'affiche le résultat souhaité qui est un tableau dans une autre interface autre que l'interface principale , jusqu'au la tout est bien mais lorsque j'ai changé de méthode c'est à dire je veux juste afficher ce tableau dans l'interface principale , j'ai créé un nouveau panel et tout , le problème c'est un probèlem d'affichage de ce tableau dans ce panel donc voici : le code du panel:
 

Code :
  1. JPanel panel_4 = new JPanel();
  2.  panel_4.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
  3.  panel_4.setBounds(115, 510, 450, 130);
  4.  getContentPane().add(panel_4);
  5.  panel_4.setLayout(null);
  6.  JLabel lblNewLabel = new JLabel("Resource Aware Planning Results" );
  7.  lblNewLabel.setFont(new Font("Times New Roman", Font.BOLD | Font.ITALIC, 14));
  8.  lblNewLabel.setBounds(125, 11, 236, 14);
  9.  panel_4.add(lblNewLabel);
  10.  JScrollPane scrollPane1 = new JScrollPane();
  11.  scrollPane1.setBounds(66, 55, 312, 49);
  12.  panel_4.add(scrollPane1);
  13.  table = new JTable();
  14.  scrollPane1.setViewportView(table);
  15.  DefaultTableModel modelres = new DefaultTableModel();
  16.  modelres.setRowCount(1);
  17.  DefaultTableModel modelres1 = new DefaultTableModel();
  18.  modelres1.setRowCount(1);


 
et voici le code du bouton Show Results:
 

Code :
  1. if ( radio3.isSelected())
  2.  {
  3.  for(int i=0; i<n;i++)
  4.     {
  5.   //int k=i+1;
  6.   String object = "T"+i;
  7.   modelres.addColumn(object);// modelres est globale ainsi que modelres1
  8.   int index=plan.NodeIndex(i, res, m);
  9.   object="N"+index;
  10.   modelres.setValueAt(object, 0, i);
  11.     }
  12.   table.setModel(modelres);
  13.  //resultsFrame.setVisible(true);
  14.  }
  15.  else if ( radio4.isSelected())
  16.  {
  17.   for(int i=0; i<n;i++)
  18.   {
  19.    //int k=i+1;
  20.    String object = "T"+i;
  21.    modelres1.addColumn(object);
  22.    int index=plan.NodeIndex(i, res, m);
  23.    object="N"+index;
  24.    modelres1.setValueAt(object, 0, i);
  25.   }
  26.    table.setModel(modelres1);
  27.   //resultsFrame.setVisible(true);
  28.      }


et il m'affiche cette erreur :  

Code :
  1. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  2. at projetPFE.GUI2.btnShowResults(GUI2.java:978)
  3. at projetPFE.GUI2$5.actionPerformed(GUI2.java:363)
  4. at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
  5. at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
  6. at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
  7. at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
  8. at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
  9. at java.awt.Component.processMouseEvent(Unknown Source)
  10. at javax.swing.JComponent.processMouseEvent(Unknown Source)
  11. at java.awt.Component.processEvent(Unknown Source)
  12. at java.awt.Container.processEvent(Unknown Source)
  13. at java.awt.Component.dispatchEventImpl(Unknown Source)
  14. at java.awt.Container.dispatchEventImpl(Unknown Source)
  15. at java.awt.Component.dispatchEvent(Unknown Source)
  16. at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
  17. at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
  18. at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
  19. at java.awt.Container.dispatchEventImpl(Unknown Source)
  20. at java.awt.Window.dispatchEventImpl(Unknown Source)
  21. at java.awt.Component.dispatchEvent(Unknown Source)
  22. at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  23. at java.awt.EventQueue.access$200(Unknown Source)
  24. at java.awt.EventQueue$3.run(Unknown Source)
  25. at java.awt.EventQueue$3.run(Unknown Source)
  26. at java.security.AccessController.doPrivileged(Native Method)
  27. at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  28. at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  29. at java.awt.EventQueue$4.run(Unknown Source)
  30. at java.awt.EventQueue$4.run(Unknown Source)
  31. at java.security.AccessController.doPrivileged(Native Method)
  32. at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  33. at java.awt.EventQueue.dispatchEvent(Unknown Source)
  34. at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  35. at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  36. at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  37. at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  38. at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  39. at java.awt.EventDispatchThread.run(Unknown Source)


 
je sais pas honnetement comment fixer cette errur  
 
je serai très reconnaissonte si vous pouvez m'aider
 
Merci d'avance


---------------
when there is a will there is a way
mood
Publicité
Posté le 26-11-2013 à 03:56:09  profilanswer
 

n°2211682
willy le k​id
Posté le 26-11-2013 à 12:42:26  profilanswer
 

Tu fais une action sur une instance nulle d'un objet
à la ligne
  at projetPFE.GUI2.btnShowResults(GUI2.java:978)
 
Que fais tu en ligne 978 ?

n°2211706
manel1989
Posté le 26-11-2013 à 15:17:18  profilanswer
 

Salut
 
j'ai fais ça :

Code :
  1. modelres.addColumn(object);


 
merci d'avance


---------------
when there is a will there is a way
n°2211720
willy le k​id
Posté le 26-11-2013 à 16:11:46  profilanswer
 

modelres est null.
Il est probable que tu l'a déclaré, mais pas instancié.
Tu mets un point d'arrêt et tu joues l'appli en mode debug ...


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  afficher le contenue d'un tableau dans une interface graphique

 

Sujets relatifs
afficher une adresse memoire sans printfFaire un tri dans un tableau avec un nombre de colonnes et lignes aléa
[résolu] Mapping d'image sous Zendafficher vraie url pour un mirroir de site stocké en local ?
[CSS] Cacher / afficher ligne tableauComment dupliquer certaines colonnes d'un tableau en javascript?
Graphique à partir des données d'une combobox 
Plus de sujets relatifs à : afficher le contenue d'un tableau dans une interface graphique


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR