Bonjour,
j'essaie d'ajouter une JComboBox à une fenêtre pour créer un nouvel article, cette combobox, doit m'afficher les catégories d'article.
Seulement, avec le code ci-dessous, ma combobox m'affiche l'adresse mémoire des objets contenu dans mon tableau.
Je voudrais uniquement voir apparaître les noms des catégories.
méthode de mon controler, qui affiche la fenêtre pour créer un article:
La class de ma fenêtre pour créer un article:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 public void showFormCreateArticle() { IntDAO lectureCat = DAOFactory.getDAO("CategorieArticleDAO"); this.listCategories = lectureCat.readAllObject(); FormCreateArticle formCreateArticle = new FormCreateArticle(this, listCategories); formCreateArticle.setVisible(true); }
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 package be.iepscfjemelle.projet_sgbd_v3.vues; import be.iepscfjemelle.projet_sgbd_v3.controler.Controler; import be.iepscfjemelle.projet_sgdb_v3.model.Article; import be.iepscfjemelle.projet_sgdb_v3.model.CategorieArticle; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.List; import javafx.scene.control.ComboBox; import javax.swing.ComboBoxModel; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; /** * Formulaire d'ajout d'un article */ public class FormCreateArticle extends JDialog implements ActionListener { /** * Attributs */ private final Controler contr; private final List list; /** * Attributs graphiques */ private JTextField fieldPartNumber, fieldNom, fieldPrix, fieldFabriquant, fieldStock; private JCheckBox checkActif; private JComboBox comboCategorie; private JButton accueil, valider; /** * Constructeur * * @param contr */ public FormCreateArticle(Controler contr, List list) { this.contr = contr; this.list = list; initComponents(); } public void initComponents() { //Config de la fenêtre setTitle("Création d'article"); setSize(500, 700); setModal(true); setResizable(false); setLocationRelativeTo(null); setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); Container contenu1 = getContentPane(); //Config du grid layout (Nlignes, NCol, H gap, V gap) contenu1.setLayout(new GridLayout(9, 1, 20, 10)); //fenetre de confirmation quand clic croix addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { int confirmed = JOptionPane.showConfirmDialog(null, "Voulez-vous quitter la fenêtre sans sauvegarder?", "Quitter création client", JOptionPane.YES_NO_OPTION); if (confirmed == JOptionPane.YES_OPTION) { setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); } else { setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); } } }); //form field Part Number JPanel panel1 = new JPanel(); panel1.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel labelPartNumber = new JLabel("Part Number:"); labelPartNumber.setPreferredSize(new Dimension(150, 30)); panel1.add(labelPartNumber); fieldPartNumber = new JTextField(); fieldPartNumber.setPreferredSize(new Dimension(250, 30)); panel1.add(fieldPartNumber); contenu1.add(panel1); //form field Nom JPanel panel2 = new JPanel(); panel2.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel labelNom = new JLabel("Nom de l'article:"); labelNom.setPreferredSize(new Dimension(150, 30)); panel2.add(labelNom); fieldNom = new JTextField(); fieldNom.setPreferredSize(new Dimension(250, 30)); panel2.add(fieldNom); contenu1.add(panel2); //form field Prix JPanel panel3 = new JPanel(); panel3.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel labelPrix= new JLabel("Prix de l'article:"); labelPrix.setPreferredSize(new Dimension(150, 30)); panel3.add(labelPrix); fieldPrix = new JTextField(); fieldPrix.setPreferredSize(new Dimension(250, 30)); panel3.add(fieldPrix); contenu1.add(panel3); //CheckBox actif / non actif JPanel panel4 = new JPanel(); panel4.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel labelActif = new JLabel("Actif / non actif: "); labelActif.setPreferredSize(new Dimension(150, 30)); panel4.add(labelActif); checkActif = new JCheckBox("Actif"); checkActif.setSelected(true); panel4.add(checkActif); contenu1.add(panel4); //form field Fabriquant JPanel panel5 = new JPanel(); panel5.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel labelFabriquant = new JLabel("Fabriquant:"); labelFabriquant.setPreferredSize(new Dimension(150, 30)); panel5.add(labelFabriquant); fieldFabriquant = new JTextField(); fieldFabriquant.setPreferredSize(new Dimension(250, 30)); panel5.add(fieldFabriquant); contenu1.add(panel5); //form field Stock JPanel panel6 = new JPanel(); panel6.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel labelStock = new JLabel("Quantité en stock:"); labelStock.setPreferredSize(new Dimension(150, 30)); panel6.add(labelStock); fieldStock = new JTextField(); fieldStock.setPreferredSize(new Dimension(250, 30)); panel6.add(fieldStock); contenu1.add(panel6); //form Combo Catégorie JPanel panel7 = new JPanel(); panel7.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel labelCategorie = new JLabel("Catégorie:"); labelCategorie.setPreferredSize(new Dimension(150, 30)); panel7.add(labelCategorie); comboCategorie = new JComboBox(list.toArray()); panel7.add(comboCategorie); contenu1.add(panel7); //form accueil JPanel panel8 = new JPanel(); panel8.setLayout(new FlowLayout(FlowLayout.CENTER)); accueil = new JButton("Accueil"); accueil.addActionListener(this); panel8.add(accueil); contenu1.add(panel8); //form valider panel8.setLayout(new FlowLayout(FlowLayout.CENTER)); valider = new JButton("Valider"); valider.addActionListener(this); panel8.add(valider); contenu1.add(panel8); } @Override public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }
Partager