Bonjour, j'ai vue qu'il y avait beaucoup de posts sur ce sujet mais aucun ne règle mon problème, (je viens de débuter en java).
J'aimerai rafraîchir le contenue de ma JComboBox en fonction d'un choix d'une JCheckBox. j'ai essayer avec repaint() ou revalidate() ou updateUI() ou removeAllItems() mais rien ne marche, ma JCombobox ce vide mais n’affiche pas les nouvelles valeur. Pouvez vous m'aider merci .
La classe :
Le main :
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 import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JCheckBox; import javax.swing.JComboBox; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JCheckBox; import javax.swing.JComboBox; public class Structure extends JFrame { JPanel content = new JPanel(); JCheckBox prot_structure = new JCheckBox("protéine"); JCheckBox adn_structure = new JCheckBox("ADN"); String[] tab_matrice; JComboBox c_matrice = new JComboBox(); public Structure(){ // Création de la fenetre this.setTitle("t"); this.setSize(900, 600); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); //JCheckBox-------------------------------------------------------------------------- JPanel f_structure = new JPanel(); JLabel m_structure = new JLabel("Type de structure :"); adn_structure = new JCheckBox("ADN"); prot_structure = new JCheckBox("protéine"); f_structure.add(m_structure); f_structure.add(adn_structure); f_structure.add(prot_structure); content.add(f_structure); //Définition de l'action adn_structure.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (((JCheckBox)e.getSource()).isSelected() == true){ c_matrice.removeAllItems(); tab_matrice = new String[] {"unitaire", "transition//transvertion"}; c_matrice = new JComboBox(tab_matrice); c_matrice.setSelectedIndex(0); c_matrice.repaint(); c_matrice.revalidate(); c_matrice.updateUI(); prot_structure.setSelected(false); } } }); //Définition de l'action prot_structure.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (((JCheckBox)e.getSource()).isSelected() == true){ c_matrice.removeAllItems(); tab_matrice = new String[] {"BLOSUM45", "BLOSUM50", "BLOSUM62", "BLOSUM80", "BLOSUM90", "PAM30", "PAM70", "PAM250"}; c_matrice = new JComboBox(tab_matrice); c_matrice.setSelectedIndex(2); c_matrice.repaint(); c_matrice.revalidate(); c_matrice.updateUI(); adn_structure.setSelected(false); } } }); //JComboBox-------------------------------------------------------------------------- JPanel f_matrice = new JPanel(); JLabel m_matrice = new JLabel("Choix de la matrice :"); f_matrice.add(m_matrice); f_matrice.add(c_matrice); content.add(f_matrice); this.getContentPane().add(content); this.setVisible(true); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 public class test { public static void main(String[] args) { Structure fen = new Structure(); } }
Partager