A voir également:
- Remplir jtable
- Organigramme a remplir word - Guide
- Comment remplir un document pdf - Guide
- Comment remplir un tableau excel reçu par mail - Forum Excel
- Copiez l'image dans un logiciel d'édition d'images ou un outil en ligne comme js paint ou pixlr e. remplissez les cases en suivant le code couleur. des cases supplémentaires vont se remplir automatiquement. que représente le dessin ? ✓ - Forum Windows
- Excel remplir automatiquement une cellule en fonction d'une autre ✓ - Forum Excel
4 réponses
Je viens d'essayer ton code et ça fonctionne (cf. screenshot.png)... Où est le problème ?
Remarque : il y a plus élégant que de créer un tableau très grand initialement vide et de changer les cases. On peut utiliser un Model pour ajouter des lignes au fur et à mesure.
Remarque : il y a plus élégant que de créer un tableau très grand initialement vide et de changer les cases. On peut utiliser un Model pour ajouter des lignes au fur et à mesure.
private DefaultTableModel model; private JTable getTable() { if (table==null) { model = new DefaultTableModel(); model.setColumnIdentifiers(entetes); table = new JTable(model); } return table; } private void remplir() throws IOException { Scanner sc = new Scanner(new File("sauve_login.txt")); while (sc.hasNextLine()) model.addRow(sc.nextLine().split(";")); sc.close(); }
Est-ce que l'on parle bien du même code ? Parce que là il t'indique une erreur dans la méthode remplir() à la ligne 114, alors que moi cette méthode va des lignes 74 à 95.
Cependant vu le message d'erreur dont il s'agit, je pencherais pour un problème ici :
Dans ce cas il s'agit surtout d'une erreur dans le fichier, puisque l'on suppose a priori qu'il contient sur chaque ligne quelque chose de la forme "designation;PU"
Tu peux alors changer ton code comme ceci :
Remarque : si tu utilises mon code, tu n'auras pas ce problème là, mais par contre tu auras une case vide pour chaque champ manquant.
Cependant vu le message d'erreur dont il s'agit, je pencherais pour un problème ici :
PU = tabChaine[1];En effet, si tu n'as pas de point-virgule sur une ligne, le split(";") renverra un tableau tabChaine avec une seule case, et il y aura une erreur d'accès quand on essaye de lire la seconde case.
Dans ce cas il s'agit surtout d'une erreur dans le fichier, puisque l'on suppose a priori qu'il contient sur chaque ligne quelque chose de la forme "designation;PU"
Tu peux alors changer ton code comme ceci :
String[] tabChaine = ligne.split(";");// decoup de chaque ligne if (tabChaine!=null && tabChaine.length==2) { designation = tabChaine[0]; PU = tabChaine[1]; // code propre au jtable table.setValueAt(designation, row, 0); table.setValueAt(PU, row, 1); } else System.err.printf("Ligne %d invalide :\n\t%s\n",row,ligne);
Remarque : si tu utilises mon code, tu n'auras pas ce problème là, mais par contre tu auras une case vide pour chaque champ manquant.
bonjour KX je comprend pas ,ma jframe s'affiche mais quand je clique sur remplir ce qu'il me met:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at methodologie_projet.RemplirJTable.remplir(RemplirJTable.java:114)
at methodologie_projet.RemplirJTable.access$0(RemplirJTable.java:99)
at methodologie_projet.RemplirJTable$2.actionPerformed(RemplirJTable.java:88)
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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
merci pour ton aide...
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at methodologie_projet.RemplirJTable.remplir(RemplirJTable.java:114)
at methodologie_projet.RemplirJTable.access$0(RemplirJTable.java:99)
at methodologie_projet.RemplirJTable$2.actionPerformed(RemplirJTable.java:88)
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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
merci pour ton aide...