Bonjour bonjour,
Dans mon application, la première fois que j'appelle la méthode qui va m'afficher les datas dans les JLabels, cela fonctionne.
Cependant, lorsque j'appelle cette methode depuis un certain listener, je suis obligé de ré instancier les labels, autrement j'ai un NullPointer.
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 @Override public void lireQuestionDansIhm(T_Question q) { if (q == null) { System.out.println("Y U DON'T SHOW URSELF ???" + q); } else { System.out.println(jLabel_Qnumber); if (jLabel_Qnumber == null) { jLabel_Qnumber = new JLabel(); } if (jLabel_question == null) { jLabel_question = new JLabel(); } jLabel_Qnumber.validate(); jLabel_question.validate(); jLabel_Qnumber.setText(q.getNumber().toString()); jLabel_question.setText(q.getQuestion()); jLabel_Qnumber.revalidate(); jLabel_question.revalidate(); System.out.println(" q : " + q.getQuestion()); System.out.println("JLabel_QNumber.getText() " + jLabel_Qnumber.getText()); System.out.println("JLabel_question.getText() " + jLabel_question.getText()); } }
Et pourtant ...
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 @Override public void lireNextQuestionDansIhm(T_Question q) { JLabel jLabel_Qnumber = new JLabel(); JLabel jLabel_question = new JLabel(); if (q == null) { System.out.println("Y U DON'T SHOW URSELF ???" + q); } else { String sq = q.getQuestion(); String sPk = q.getPKquestion().toString(); //jLabel_Qnumber.setText(sPk); //jLabel_question.setText(sq); lireQuestionDansIhm(q); System.out.println(sq + " et pk_q = " + sPk); } }
Les JLabels restent avec la première série de datas et ne veulent pas changer visuellement, pourtant si on utilise la méthode getText() on peut bel et bien voir que la PK numéro 2 ainsi que la question correspondante devrait être afficher.
Ah et pour les méthodes validate et revalidate c'était juste pour tester si cela rafraîchissait vraiment.
Cordialement,
RetributionX
Partager