Bonsoir à toutes et à tous,
J'ai une interface où il y a deux jComboBox. Mes deux jcombobox se remplissent grâce à un vector résultat d'une fonction. Jusque la tout va bien, mais le problème vient du fait que la fonction qui remplit le deuxième jcombobox prend en paramètre la valeur choisie dans le premier jcombobox.
Voici le code des deux jcombobox
Et là c'est l'appel à ces jcombox dans ma frame
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 private JComboBox getJComboBoxinst() throws SQLException, ClassNotFoundException { if (jComboBoxinst == null) { AvecBase jiji=new AvecBase(); Vector v=jiji.contexte(); jComboBoxinst = new JComboBox(v); jComboBoxinst.setBounds(new Rectangle(181, 30, 129, 22)); jComboBoxinst.addItemListener(this); } return jComboBoxinst; } public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if(jComboBoxinst.getSelectedItem()!=null){ String test=(String)jComboBoxinst.getSelectedItem(); try { jComboBoxniv.setEnabled(true); jComboBoxniv=getJComboBoxniv(test); jComboBoxniv.repaint();//revalidate(); } catch (Exception e1) {e1.printStackTrace();} jComboBoxniv.setEnabled(true); } } else { } } private JComboBox getJComboBoxniv(String test) throws SQLException, ClassNotFoundException { if (jComboBoxniv == null) { AvecBase jiji=new AvecBase(); Vector v=jiji.niveau(test); jComboBoxniv = new JComboBox(v); jComboBoxniv.setBounds(new Rectangle(180, 76, 129, 25)); } return jComboBoxniv; }
Je ne vous remercierai jamais assez pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 //jPanel jPanel.add(getJComboBoxinst(), gbc); //... jComboBoxniv=getJComboBoxniv(null); jComboBoxniv.setEnabled(false); jPanel.add(jComboBoxniv, gbc);
Partager