Bonjour,
j'ai une application utilisant un ComboBox et un jList. lorsque je clique un item du ComboBox, une liste d'éléments s'affiche dans la jList, et lorsque je clique sur la jList, des données s'affichent sur des textField. J'ai donc des Listeners sur le ComboBox et sur la jList. le problème est qe :
-avant de cliquer sur la jList, tout marche bien
- une fois que je clique sur la jList et que je clique ensuite sur un item du comboBox, une erreur s'affiche et le menu déroulant du combobox ne remonte pas mais le résultat s'affiche dans la jList.
l'erreur est la suivante:
L'erreur me renvoie aux lignes du code qui sont en rouge:
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 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at outildediagnostic.Expert$StyleListListener.valueChanged(Expert.java:251) at javax.swing.JList.fireSelectionValueChanged(JList.java:1317) at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1331) at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:187) at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167) at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:214) at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:408) at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:417) at javax.swing.DefaultListSelectionModel.removeSelectionIntervalImpl(DefaultListSelectionModel.java:510) at javax.swing.DefaultListSelectionModel.clearSelection(DefaultListSelectionModel.java:422) at javax.swing.JList.clearSelection(JList.java:1578) at javax.swing.JList.setModel(JList.java:1216) at javax.swing.JList.setListData(JList.java:1229) at outildediagnostic.Expert.jComboBox1_itemStateChanged(Expert.java:226) at outildediagnostic.Expert$2.itemStateChanged(Expert.java:140) at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1162) at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1210) at javax.swing.JComboBox.contentsChanged(JComboBox.java:1266) at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:100) at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:88) at javax.swing.JComboBox.setSelectedItem(JComboBox.java:551) at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:597) at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:808) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:232) at java.awt.Component.processMouseEvent(Component.java:5488) at javax.swing.JComponent.processMouseEvent(JComponent.java:3126) at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:476) at java.awt.Component.processEvent(Component.java:5253) at java.awt.Container.processEvent(Container.java:1966) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822) at java.awt.Container.dispatchEventImpl(Container.java:2010) at java.awt.Window.dispatchEventImpl(Window.java:1774) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Merci pour votre aide.
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 private StyleListListener liste = new StyleListListener(); //Le comboBox void jComboBox1_itemStateChanged(ItemEvent e) { selected = jComboBox1.getSelectedItem(); String[] data = new String [size]; /* Traitement */ jList1.removeAll(); jList1.setListData(data); jList1.addListSelectionListener(liste); } //La jList class StyleListListener implements ListSelectionListener { public void valueChanged (ListSelectionEvent e) { boule = e.getValueIsAdjusting(); if (boule) return; selected1 = jList1.getSelectedValue(); if (selected1.equals(s)) bool = true;// bool :boolean et s: string }}
Partager