Bonjour,

Comme l'indique le titre, je dispose d'une Map<String, Joueur> et j'aimerais remplir ma JTable avec les données de ma map.

Chaque colonne possède un nom fixe et je veux remplir les lignes avec les données des joueurs.(Mon objet joueur possède des attributs String du type nom prénom age club....)

J'aimerais avoir un tableau comme ça :

Nom : Capture.PNG
Affichages : 338
Taille : 8,3 Ko


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	public void showtable (Map<String, Joueur> data) throws IllegalAccessException, NoSuchFieldException{
 
		 String[] columnNames = new String[10];
 
	        columnNames[0]="a";
	        columnNames[1]="b";
	        columnNames[2]="c";
	        columnNames[3]="d";
	        columnNames[4]="e";
	        columnNames[5]="a";
	        columnNames[6]="b";
	        columnNames[7]="c";
	        columnNames[8]="d";
	        columnNames[9]="e";
 
 
 
 
	        Object[][] dataForTable = getTableData(data, columnNames);
	        JTable table = new JTable(dataForTable, columnNames);
 
	        JFrame frame = new JFrame();
	        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        JScrollPane scrollPane = new JScrollPane(table);
	        table.setFillsViewportHeight(true);
 
	        frmTnr.getContentPane().add(scrollPane, BorderLayout.CENTER);
	        frmTnr.setSize(900, 500);
	        frmTnr.setVisible(true);
 
	}
 
 
	private static Object[][] getTableData(Map<String, Joueur> data, String[] columns) throws IllegalAccessException, NoSuchFieldException {
 
	    Object[][] dataForTable = new Object[data.size()][columns.length];
 
	    fot(int i =0; i<data.size();i++){
	    for (int column = 0; column < columns.length; column++) {
	    for (Map.Entry<String, Joueur> entry : data.entrySet()) {
 
 
 
	            Joueur value = entry.getValue();
	            String test = value.getNom();
	            System.out.println(test);
 
	            dataForTable[i][column] = test;
	        }
	    }
           }
 
	    return dataForTable;
	}
Je ne sais pas si je suis sur la bonne piste mais je suis bloqué, je n'arrive pas a mettre chaque valeur de mon objet dans chaque cellule de mon tableau,

Merci d'avance