Bonjour à tous, je suis devant un petit soucis avec un jtable. J'ai un logiciel de gestion à créer, j'ai donc une fenetre principale avec des menus. Quand je clique sur l'item "client" j'ai un panel defini dans une autre classe et composé d'un tableau qui s'affiche avec toutes les info sur tous mes clients. Le probleme c'est que l'utilisateur doit etre capable d'afficher les colonnes qu'il souhaite et même d'en créer. Pour cela j'ai un bouton "modifier" qui appelle un formulaire defini dans une autre classe composé de deux jCombobox (une avec les colonnes de base et l'autre avec les colonnes affichées dans le tableau) et des boutons pour ajouter ou supprimer des propriétés.
Pour l'instant je n'ai pas de base de données donc toutes les valeurs sont rentrées manuellement, seulement je n'arrive pas a donner les valeur de ma combobox(celle qui contient les colonnes affichées dans le tableau) à la variable qui initialise les colonnes du tableau (qui est dans un fichier différent).
Si quelqu'un pouvait me donner un coup de pouce... Merci d'avance.
Mon panel avec le tableau:
Mon petit formulaire:
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 import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; public class tableauclt extends JPanel { private JScrollPane jScrollPane = null; private JTable jTtableauclient = null; private JButton jBmodifiercolonne = null; String[] columnNames = {"First Name","Last Name","Sport","# of Years","Vegetarian"}; Object[][] data = {{"Mary", "Campione","Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml","Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath","Knitting", new Integer(2), new Boolean(false)}, {"Sharon", "Zakhour","Speed reading", new Integer(20), new Boolean(true)}, {"Philip", "Milne","Pool", new Integer(10), new Boolean(false)}, {"Isaac", "Rabinovitch", "Nitpicking", new Integer(1000), new Boolean(false)} }; public tableauclt() { super(); initialize(); } /** * This method initializes this * */ private void initialize() { this.setLayout(null); GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = graphicsEnvironment .getMaximumWindowBounds(); this.setBounds(bounds); this.add(getJScrollPane(), null); this.setVisible(true); this.add(getJBmodifiercolonne(), null); } /** * This method initializes jScrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setBounds(new Rectangle(0, 18, 1023, 720)); jScrollPane.setViewportView(getJTtableauclient()); } return jScrollPane; } /** * This method initializes jTtableauclient * * @return javax.swing.JTable */ public JTable getJTtableauclient() { if (jTtableauclient == null) { jTtableauclient = new JTable(); jTtableauclient = new JTable(data,columnNames); jTtableauclient.setAutoCreateRowSorter(true); jTtableauclient.setVisible(true); } return jTtableauclient; } /** * This method initializes jBmodifiercolonne * * @return javax.swing.JButton */ private JButton getJBmodifiercolonne() { if (jBmodifiercolonne == null) { jBmodifiercolonne = new JButton(); jBmodifiercolonne.setBounds(new Rectangle(5, 4, 155, 12)); jBmodifiercolonne.setText("Choisir les colonnes"); jBmodifiercolonne.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { modiftablclt md = new modiftablclt(); md.getJFchangercolonne(); } }); } return jBmodifiercolonne; } } // @jve:decl-index=0:visual-constraint="0,1"
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 import java.awt.Rectangle; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JComboBox; public class modiftablclt { private JFrame jFchangercolonne = null; // @jve:decl-index=0:visual-constraint="306,67" private JPanel jContentPane = null; private JTextField jTFcolonne = null; private JLabel jLabel = null; private JButton jBajoutercolonne = null; private JButton jBsupprimercolonne = null; private JButton jBadd = null; private JComboBox jCBbase = null; private JComboBox jCBtable = null; private JButton jBremove = null; private JButton jButton = null; /** * This method initializes jFchangercolonne * * @return javax.swing.JFrame */ public JFrame getJFchangercolonne() { if (jFchangercolonne == null) { jFchangercolonne = new JFrame(); jFchangercolonne.setTitle("Choix des colonnes du tableau de clients"); jFchangercolonne.setVisible(true); jFchangercolonne.setBounds(new Rectangle(200, 100, 408, 183)); jFchangercolonne.setContentPane(getJContentPane()); } return jFchangercolonne; } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jLabel = new JLabel(); jLabel.setBounds(new Rectangle(1, 10, 51, 20)); jLabel.setText("Colonne"); jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(getJTFcolonne(), null); jContentPane.add(jLabel, null); jContentPane.add(getJBajoutercolonne(), null); jContentPane.add(getJBsupprimercolonne(), null); jContentPane.add(getJBadd(), null); jContentPane.add(getJCBbase(), null); jContentPane.add(getJCBtable(), null); jContentPane.add(getJBremove(), null); jContentPane.add(getJButton(), null); } return jContentPane; } /** * This method initializes jTFcolonne * * @return javax.swing.JTextField */ private JTextField getJTFcolonne() { if (jTFcolonne == null) { jTFcolonne = new JTextField(); jTFcolonne.setBounds(new Rectangle(61, 10, 119, 20)); } return jTFcolonne; } /** * This method initializes jBajoutercolonne * * @return javax.swing.JButton */ private JButton getJBajoutercolonne() { if (jBajoutercolonne == null) { jBajoutercolonne = new JButton(); jBajoutercolonne.setBounds(new Rectangle(151, 79, 96, 16)); jBajoutercolonne.setText("Ajouter"); jBajoutercolonne.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { jCBtable.addItem(jCBbase.getSelectedItem()); } }); } return jBajoutercolonne; } /** * This method initializes jBsupprimercolonne * * @return javax.swing.JButton */ private JButton getJBsupprimercolonne() { if (jBsupprimercolonne == null) { jBsupprimercolonne = new JButton(); jBsupprimercolonne.setBounds(new Rectangle(151, 100, 96, 16)); jBsupprimercolonne.setText("Supprimer"); jBsupprimercolonne.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { jCBtable.removeItem(jCBtable.getSelectedItem()); } }); } return jBsupprimercolonne; } private JButton getJBadd() { if (jBadd == null) { jBadd = new JButton(); jBadd.setBounds(new Rectangle(195, 10, 43, 20)); jBadd.setText("+"); jBadd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { jCBbase.addItem(jTFcolonne.getText()); } }); } return jBadd; } /** * This method initializes jCBbase * * @return javax.swing.JComboBox */ private JComboBox getJCBbase() { if (jCBbase == null) { jCBbase = new JComboBox(); jCBbase.setBounds(new Rectangle(18, 79, 115, 16)); jCBbase.addItem("____________"); jCBbase.addItem("code client"); jCBbase.addItem("raison sociale"); jCBbase.addItem("adresse"); jCBbase.addItem("adresse2"); jCBbase.addItem("code postal"); jCBbase.addItem("code postal2"); jCBbase.addItem("ville"); jCBbase.addItem("ville2"); jCBbase.addItem("telephone"); jCBbase.addItem("telephone2"); jCBbase.addItem("fax"); jCBbase.addItem("fax2"); jCBbase.addItem("portable"); jCBbase.addItem("portable2"); jCBbase.addItem("e_mail"); jCBbase.addItem("site_web"); } return jCBbase; } /** * This method initializes jCBtable * * @return javax.swing.JComboBox */ private JComboBox getJCBtable() { if (jCBtable == null) { jCBtable = new JComboBox(); jCBtable.setBounds(new Rectangle(265, 79, 115, 16)); jCBtable.addItem("____________"); } return jCBtable; } /** * This method initializes jBremove * * @return javax.swing.JButton */ private JButton getJBremove() { if (jBremove == null) { jBremove = new JButton(); jBremove.setBounds(new Rectangle(250, 10, 43, 20)); jBremove.setText("-"); jBremove.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { jCBbase.removeItem(jCBbase.getSelectedItem()); } }); } return jBremove; } /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setBounds(new Rectangle(151, 133, 96, 16)); jButton.setText("OK"); } return jButton; } }
Partager