Salut à tous,
Je suis en train de faire un logiciel pour mon bahut
et j'ai un problèmeuhhh que me soule depuis maintenant pas loin de 4h...
Alors j'ai une JComboBox qui s'affiche et qui doit à la sélection d'un element de la liste, charger des données d'une base pour ensuite activer une autre combo box (enabled) et lui inserer les données...
Bon le chargement de la base ca marche nikel, rien à dire... Mais quand il s'agit de l'afficher... ca ne marche pas, sauf si je refait un setPanelXXXX() < une méthode que j'ai codé ... Vous avez déjà eu ce problème ?
Bon maintenant j'en suis (avec très très peu de méthode) à faire des gros repaint() de tout mais ca ne marche pas plus ...
Si vous voulez mon code :
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 public void setPanelCreerFiche(){ // Suppression de tout ce qu'il y avait avant this.getPanelPrincipal().removeAll(); // Affichage GridBagConstraints gbc = new GridBagConstraints(); // [...] gbc.gridx = 0; gbc.gridwidth = 1; gbc.gridy++; gbc.anchor = GridBagConstraints.BASELINE; gbc.insets = new Insets(10, 15, 0, 0); this.getPanelPrincipal().add(new JLabel("Adresse :"),gbc); gbc.gridx = 1; gbc.anchor = GridBagConstraints.CENTER; // C'est ce combo box qui doit agir sur l'autre this.getPanelPrincipal().add(this.getCreationFicheComboVille(),gbc); //[....] this.getPanelPrincipal().add(this.getCreationFicheComboRue(),gbc); // [...] } // CA MARCHE IMPEC' public JComboBox getCreationFicheComboVille(){ if(this.creationFicheComboVille == null){ String[][] tabCPVille = Adresse.getAllCPVille(); String[] entreesTableau = new String[((tabCPVille[0].length)+2)]; entreesTableau[0] = " "; for(int i = 1; i < tabCPVille[0].length+1; i++){ entreesTableau[i] = tabCPVille[0][i-1]+" - "+tabCPVille[1][i-1]; } entreesTableau[entreesTableau.length-1] = "Autre ..."; DefaultComboBoxModel model = new DefaultComboBoxModel(entreesTableau); this.creationFicheComboVille = new JComboBox(model); this.creationFicheComboVille.addActionListener(this); } return this.creationFicheComboVille; } public JComboBox getCreationFicheComboRue(){ if(this.creationFicheComboRue == null){ String[] entreesTableau = new String[1]; entreesTableau[0] = " "; DefaultComboBoxModel model = new DefaultComboBoxModel(entreesTableau); this.creationFicheComboRue = new JComboBox(model); this.creationFicheComboRue.addActionListener(this); } return this.creationFicheComboRue; } public void setCreationFicheComboRue(String[] tabCPVille){ if(this.creationFicheComboRue == null){ this.getCreationFicheComboRue(); } String[] tabRue = Adresse.getRueByCPVille(tabCPVille); DefaultComboBoxModel model = null; if(tabRue != null){ String[] entreesTableau = new String[tabRue.length+2]; entreesTableau[0] = " "; for(int i = 1; i < tabRue.length+1; i++){ entreesTableau[i] = tabRue[i-1]; } entreesTableau[entreesTableau.length-1] = "Autre ..."; model = new DefaultComboBoxModel(entreesTableau); this.creationFicheComboRue = new JComboBox(model); }else{ this.creationFicheComboRue = null; this.getCreationFicheComboRue(); } } public void actionPerformed(ActionEvent e){ Object element = e.getSource(); //[...] if(element == creationFicheComboVille){ if(creationFicheComboVille.getSelectedItem() == "Autre ..."){ this.getCreationFicheChampAutreCP().setEditable(true); this.getCreationFicheChampAutreCP().setText(""); this.getCreationFicheChampAutreVille().setEditable(true); this.getCreationFicheChampAutreVille().setText(""); for(int i = 0; i < getPanelPrincipal().getComponentCount(); i++){ getPanelPrincipal().getComponent(i).repaint(); } }else if(creationFicheComboVille.getSelectedItem() == " "){ this.getCreationFicheChampAutreCP().setEditable(false); this.getCreationFicheChampAutreCP().setText("CP"); this.getCreationFicheChampAutreVille().setEditable(false); this.getCreationFicheChampAutreVille().setText("Nom de la Ville"); this.setCreationFicheComboRue(null); this.getCreationFicheComboNumero(null).setEnabled(false); for(int i = 0; i < getPanelPrincipal().getComponentCount(); i++){ getPanelPrincipal().getComponent(i).repaint(); } }else{ this.getCreationFicheChampAutreCP().setEditable(false); this.getCreationFicheChampAutreCP().setText("CP"); this.getCreationFicheChampAutreVille().setEditable(false); this.getCreationFicheChampAutreVille().setText("Nom de la Ville"); String elementSel = (String)creationFicheComboVille.getSelectedItem(); String[] decomposition = elementSel.split(" - "); if(decomposition.length > 2){ for(int i = 2; i < decomposition.length; i++){ decomposition[1] = decomposition[1].concat(" - "+decomposition[i]); } } this.setCreationFicheComboRue(decomposition); for(int i = 0; i < getPanelPrincipal().getComponentCount(); i++){ getPanelPrincipal().getComponent(i).repaint(); } } }//[...] }
Partager