Bonjour,
j'utilise un type de treenode qui me permet de lazy loader les noeuds enfants :
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 package forms; import java.lang.reflect.Field; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.MutableTreeNode; public class FieldTreeNode extends DefaultMutableTreeNode { public boolean isFake = true; private Object target; public FieldTreeNode(Object target) { super(target.getClass().getName() + " - " + target.toString()); this.target = target; this.add(new DefaultMutableTreeNode("FK")); } public void GetChilds() { isFake = false; this.removeAllChildren(); Class cl = target.getClass(); for (Field field : cl.getFields()) { try { Object a = field.get(target); FieldTreeNode ftn = new FieldTreeNode(a); this.add((MutableTreeNode)ftn); } catch (Throwable t) { t.printStackTrace(); } } } }
de plus, je gère l'évènement treenodewillexpand pour demander au noeud de me renvoyer ses enfants si il est déroulé :
Or, j'ai une belle exception non gèrée lors de l'appel de updateUI(). Si je n'apelle pas la mise à jour du treenode, pas d'exception mais pas de mise à jour de mes enfants non plus...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { TreePath myPath = event.getPath(); if (myPath != null) { FieldTreeNode ftn = (FieldTreeNode) myPath.getLastPathComponent(); if (ftn.isFake) { ftn.GetChilds(); } } tree.updateUI(); } });
détail de l'exception :
Merci d'avance.
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 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.plaf.basic.BasicTreeUI.updateSize(BasicTreeUI.java:1709) at javax.swing.plaf.basic.BasicTreeUI.toggleExpandState(BasicTreeUI.java:2190) at javax.swing.plaf.basic.BasicTreeUI.handleExpandControlClick(BasicTreeUI.java:2176) at javax.swing.plaf.basic.BasicTreeUI.checkForClickInExpandControl(BasicTreeUI.java:2130) at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelectionImpl(BasicTreeUI.java:3495) at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3480) at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:3461) at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222) at java.awt.Component.processMouseEvent(Component.java:5485) at javax.swing.JComponent.processMouseEvent(JComponent.java:3126) 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:3889) 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)
Partager