bonjour ,
je voudrais récupérer la valeur d'un combo dans une autre fenetre et quand je metil ne l'accepte pasCode:frm1.cboVille.selectedItem.toString()
Version imprimable
bonjour ,
je voudrais récupérer la valeur d'un combo dans une autre fenetre et quand je metil ne l'accepte pasCode:frm1.cboVille.selectedItem.toString()
Peux tu envoyer l'erreur exact?
Ton cboVille est en public?
il me souligne frm1.cboVille et m'écrit no enclosing instance of the frm1 is accessible in scope.
le cboVille est public
PS : j'utilise visual editor.
Envoie ton code. L'erreur doit se situer ailleurs.
initialisation de frm1 par exemple ou ...
je veux récupérer la valeur d'lement du combo
Code:
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 import java.awt.BorderLayout; import javax.swing.JPanel; import javax.swing.JFrame; import java.awt.Dimension; import javax.swing.WindowConstants; import javax.swing.JButton; import java.awt.Rectangle; import java.util.Vector; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.JLabel; public class frmAfficheTrain extends JFrame { /** * */ private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JButton btnRechercher = null; public JComboBox cboDepart = null; private JComboBox cboArrivee = null; private JLabel jLabel = null; private JLabel jLabel1 = null; public Vector vColonnes=new Vector(); private JComboBox cboType = null; private JLabel jLabel2 = null; private JTable jtableTrain=null; public Vector vData=new Vector(); private JTable tableTrain = null; public frmAfficheTrain() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(639, 472); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setContentPane(getJContentPane()); this.setTitle("Recherche Train"); this.setVisible(true); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jLabel2 = new JLabel(); jLabel2.setBounds(new Rectangle(31, 74, 85, 31)); jLabel2.setText("Type Train"); jLabel1 = new JLabel(); jLabel1.setBounds(new Rectangle(284, 30, 92, 26)); jLabel1.setText("Ville Arrivée"); jLabel = new JLabel(); jLabel.setBounds(new Rectangle(27, 25, 87, 29)); jLabel.setText("Ville Départ"); jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(getBtnRechercher(), null); jContentPane.add(getCboDepart(), null); jContentPane.add(getCboArrivee(), null); jContentPane.add(jLabel, null); jContentPane.add(jLabel1, null); jContentPane.add(getCboType(), null); jContentPane.add(jLabel2, null); jContentPane.add(getTableTrain(), null); } return jContentPane; } /** * This method initializes btnRechercher * * @return javax.swing.JButton */ private JButton getBtnRechercher() { if (btnRechercher == null) { btnRechercher = new JButton(); btnRechercher.setBounds(new Rectangle(259, 375, 106, 33)); btnRechercher.setText("Rechercher"); } return btnRechercher; } /** * This method initializes cboDepart * * @return javax.swing.JComboBox */ public JComboBox getCboDepart() { if (cboDepart == null) { cboDepart = new JComboBox(); cboDepart.setBounds(new Rectangle(150, 26, 105, 28)); } return cboDepart; } /** * This method initializes cboArrivee * * @return javax.swing.JComboBox */ private JComboBox getCboArrivee() { if (cboArrivee == null) { //Vector v=new Vector<String>(); //v.addElement("TGV"); cboArrivee = new JComboBox(); cboArrivee.setBounds(new Rectangle(414, 30, 93, 25)); } return cboArrivee; } /** * This method initializes cboType * * @return javax.swing.JComboBox */ private JComboBox getCboType() { if (cboType == null) { cboType = new JComboBox(); cboType.setBounds(new Rectangle(151, 76, 107, 27)); } return cboType; } /** * This method initializes tableTrain * * @return javax.swing.JTable */ private JTable getTableTrain() { if (tableTrain == null) { //tableTrain = new JTable(); Vector<String> ligne1=new Vector<String>(); ligne1.addElement("Anis"); ligne1.addElement("Anis"); ligne1.addElement("Anis"); ligne1.addElement("Anis"); Vector<String> ligne2=new Vector<String>(); ligne2.addElement("imen"); ligne2.addElement("imen"); ligne2.addElement("imen"); ligne2.addElement("imen"); Vector<Vector<String>> data=new Vector<Vector<String>>(); data.addElement(ligne1); data.addElement(ligne2); Vector<String> v=new Vector<String>(); v.addElement("Prénom"); v.addElement("Nom"); v.addElement("couleur"); v.addElement("Homme"); tableTrain = new JTable(data, v); tableTrain.setBounds(new Rectangle(99, 146, 407, 193)); } return tableTrain; } } // @jve:decl-index=0:visual-constraint="10,10"
ne marche pasCode:frmAfficheTrain.this.cboDepart.getSelectedItem().toString()
Certes non. C'est censé vouloir dire quoi, "frmAfficheTrain.this" ? Il semble que frmAfficheTrain soit le nom d'une classe ?
Si tu veux accéder à l'élément cboDepart d'un objet de type frmAfficheTrain, il faut d'abord avoir accès à cet objet. Mettons que tu l'aies dans une variable ou un paramètre nommé frame, dans ce cas tu fais :
Note : un nom de classe doit normalement commencer par une majuscule, et puis l'intérêt des abréviations, hein... Du coup ce devrait être FrameAfficheTrain ou quelque chose de ce genre.Code:frame.cboDepart.getSelectedItem().toString()
en frmAfficheTrain est une classe qui étend jFrame , et cboVilleDepart est instancié et affiché dans frmAfficheTrain.