Salut j'ai suivi le tuto de ce site sur les jTable, j'ai éssayé de creer mon propre tableau(tableau1) et l'ai ajouté a un jPanel (jPanel1) que j'ai ajouté a mon container grçace au builder de netbeans:
ma classe Article :
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 tableau1=new JTable(new Modele()); jPanel1.add(new JScrollPane(tableau1), BorderLayout.CENTER); jPanel1.revalidate(); jPanel1.repaint(); this.revalidate(); this.repaint(); [...] public class Modele extends AbstractTableModel { private List<Article> articles=new ArrayList<Article>(); private String[] titresJT1={"REF","Description", "Prix unitaire", "Quantité", "Total", "Supprimer"}; public Modele() { super(); addArticle(new Article("refe", "descript", "prix", "quantit", "tot")); } public int getRowCount() { return articles.size(); } public int getColumnCount() { return titresJT1.length; } @Override public String getColumnName(int columnIndex) { return titresJT1[columnIndex]; } public Object getValueAt(int rowIndex, int columnIndex) { switch(columnIndex) { case 0: return articles.get(rowIndex).getReference(); case 1: return articles.get(rowIndex).getDescription(); case 2: return articles.get(rowIndex).getPrixUnitaire(); case 3: return articles.get(rowIndex).getQuantite(); case 4: return articles.get(rowIndex).getTotal(); case 5: return articles.get(rowIndex).getBouton(); default: return null; } } private void addArticle(Article article) { articles.add(article); fireTableRowsInserted(articles.size() -1, articles.size() -1); } }
Mais voila rien ne s'affiche, j'ai pourtant suivi le tuto a la lettre.
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 import javax.swing.JButton; /** * * @author pj */ public class Article extends Objet { private String reference; private String description; private String prixUnitaire; private String quantite; private String total; private JButton bouton; public Article(String reference, String description, String prixUnitaire, String quantite, String total) { this.reference=reference; this.description=description; this.prixUnitaire=prixUnitaire; this.total=total; this.bouton=new JButton("Supprimer"); } /** * @return the reference */ public String getReference() { return reference; } /** * @param reference the reference to set */ public void setReference(String reference) { this.reference = reference; } /** * @return the description */ public String getDescription() { return description; } /** * @param description the description to set */ public void setDescription(String description) { this.description = description; } /** * @return the prixUnitaire */ public String getPrixUnitaire() { return prixUnitaire; } /** * @param prixUnitaire the prixUnitaire to set */ public void setPrixUnitaire(String prixUnitaire) { this.prixUnitaire = prixUnitaire; } /** * @return the quantité */ public String getQuantite() { return quantite; } /** * @param quantité the quantité to set */ public void setQuantite(String quantité) { this.quantite = quantité; } /** * @return the total */ public String getTotal() { return total; } /** * @param total the total to set */ public void setTotal(String total) { this.total = total; } /** * @return the bouton */ public JButton getBouton() { return bouton; } /** * @param bouton the bouton to set */ public void setBouton(JButton bouton) { this.bouton = bouton; } }
Merci de votre aide
Partager