Remplir un Jtable a partir d'un tableau

coach872 Messages postés 9 Date d'inscription mardi 6 avril 2010 Statut Membre Dernière intervention 9 février 2012 - 5 mai 2010 à 18:59
coach872 Messages postés 9 Date d'inscription mardi 6 avril 2010 Statut Membre Dernière intervention 9 février 2012 - 5 mai 2010 à 22:56
salut,
j'ai un tableau que j'ai crée a partir d'un fichier csv je veut maintenant l'inserer dans un Jtable voici mon code de lecture d'un fichier csv
try{

File file = new File("exemple.csv");
 fr = new FileReader(file);
BufferedReader bfr =new BufferedReader(fr);
String line = null;
int row = 0;
int col = 0;
 
//read each line of text file
while((line = bfr.readLine()) != null)
{
StringTokenizer stk = new StringTokenizer(line,";");
while (stk.hasMoreTokens())
{
//get next token and store it in the array
facture[row][col] = stk.nextToken();
System.out.print(facture[row][col]+"-");
col++;
}
System.out.println("");
row++;
}[code=java]

je veut maintenant insérer la table facture dans un JTable voici mon nouvel code
[code=java]
try{

File file = new File("exemple.csv");
 fr = new FileReader(file);
BufferedReader bfr =new BufferedReader(fr);
String line = null;
int row = 0;
int col = 0;
 
//read each line of text file
while((line = bfr.readLine()) != null)
{
StringTokenizer stk = new StringTokenizer(line,";");
while (stk.hasMoreTokens())
{
//get next token and store it in the array
facture[row][col] = stk.nextToken();

 
        Object[][] donnees = {facture[row][col]};
              
        String[] entetes = {"login", "numéro de pc", "adresse ip", "heure début", "heure fin","duré","montant a payé","date"};

        JTable tableau = new JTable(donnees, entetes);

      panneau3 .add(tableau.getTableHeader(), BorderLayout.NORTH);
       panneau3.add(tableau, BorderLayout.CENTER);

        pack();
 
System.out.print(facture[row][col]+"-");
col++;
}
System.out.println("");
row++;
}
 
//close the file
bfr.close();
}
catch(Exception ea) {
   ea.printStackTrace();
}

1 réponse

coach872 Messages postés 9 Date d'inscription mardi 6 avril 2010 Statut Membre Dernière intervention 9 février 2012
5 mai 2010 à 22:56
salut,
SVP si quelqu'un peut m'aider
0
Rejoignez-nous