OVH Cloud OVH Cloud

problème de casting ?

2 réponses
Avatar
yvon.thoravalNO-SPAM
j'ai modifié une partie d'une méthode, avant je faisais :

datePanel.add(monthsList.gridbag);

monthsList étant une JComboBox

ça marchait deux-peccables (thanks to Farid :))

j'ai trois JComboBox namely :

daysList, monthsList et yearsList (représentant une date)

maintenant je voudrais ajouter la possibilté de disposer les trois
JComboBox dans un ordre quelconque controlé par une string, passée en
argument (dateSequence), du genre :

"dmy", "dym" etc...

alors, je me batis une HashMap :

Map dsl = new HashMap();
dsl.put("d", daysList);
dsl.put("m", monthsList);
dsl.put("y", yearsList);

je vérifie que l'user a rentré une bonne string de combinaison :

ArrayList possibleSequence = new ArrayList();
possibleSequence.add("dmy");
possibleSequence.add("dym");
possibleSequence.add("mdy");
possibleSequence.add("myd");
possibleSequence.add("ymd");
possibleSequence.add("ydm");

if (!possibleSequence.contains(this.dateSequence)) {
this.dateSequence = "dmy";
}

je prends la première lettre de la combinaison :
String first = this.dateSequence.substring(0, 1);
la seconde :
String second = this.dateSequence.substring(1, 2);
la troisième :
String third = this.dateSequence.substring(2);

pas de pb jusque là...

puis, donc au lieu de faire datePanel.add(monthsList.gridbag); (par
exemple) je fais :

datePanel.add(((JComboBox)dsl.get(first)).gridbag);

et le compilo me jette par :

[javac]
/Users/yvonthor/Sites/ultrid/modules/org-ultrid-yvonthor/jcombo-date/org
/ultrid/yvonthor/jcombo_date/DateCombo.java:154: cannot resolve symbol
[javac] symbol : variable gridbag
[javac] location: class javax.swing.JComboBox
[javac] datePanel.add(((JComboBox)dsl.get(first)).gridbag);
[javac] ^

(bien sûr idem pour les 3)

je ne comprends pas où est le pb car ((JComboBox)dsl.get(first)) est
bien une JComboBox.

je ne vois pas ce qui pose pb, et vous ???

--
yt

2 réponses

Avatar
Farid
ça marchait deux-peccables (thanks to Farid :))


;)

datePanel.add(((JComboBox)dsl.get(first)).gridbag);


heu ==> datePanel.add(((JComboBox)dsl.get(first)),gridbag);
virgule avant gridbag, pas un point !


Farid.

Avatar
yvon.thoravalNO-SPAM
Farid wrote:

heu ==> datePanel.add(((JComboBox)dsl.get(first)),gridbag);
virgule avant gridbag, pas un point !


et M&@RDE !!!
tanks again !!!

--
yt