Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error in painting JTree

0 views
Skip to first unread message

Igor Buzatovic

unread,
Jan 27, 2003, 7:28:26 AM1/27/03
to
Hi.
I have a Jtree with DefaultTreeModel.


SometimesI have to replace some node with another because data has changed.
So I do this
I find original node which is child of root node and I replace it with new
node.

DefaultMutableTreeNode original=findNode(int data);
original=newNode;
tree.revalidate();
tree.repaint();

then I get error :

java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTreeUI.paintRow(BasicTreeUI.java:1375)
at javax.swing.plaf.basic.BasicTreeUI.paint(BasicTreeUI.java:1171)
at javax.swing.plaf.metal.MetalTreeUI.paint(MetalTreeUI.java:143)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
at javax.swing.JComponent.paintComponent(JComponent.java:541)
at javax.swing.JComponent.paint(JComponent.java:808)
at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4771)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4724)
at javax.swing.JComponent._paintImmediately(JComponent.java:4668)
at javax.swing.JComponent.paintImmediately(JComponent.java:4477)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQu
eueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:197)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

why is this error rising?


Jason Teagle

unread,
Jan 27, 2003, 9:21:44 AM1/27/03
to

"Igor Buzatovic" <igor.bu...@willevolve.com> wrote in message
news:b138jd$3jk$1...@sunce.iskon.hr...

> DefaultMutableTreeNode original=findNode(int data);
> original=newNode;
> tree.revalidate();
> tree.repaint();

Here, "original" is a local variable (because you declare it on the same
line) - and thus, replacing it with "newNode" only changes the reference
stored in that local variable - it does nothing to the object [memory block]
referenced by "original", and thus nothing to the tree itself... this may be
the root (no pun intended) of your problem.


--
---
Jason Teagle
ja...@teagster.co.uk

A list of programming resources I use:
E-mail lists: www.windev.org, www.beginthread.com, www.codecipher.com
Newsgroups: comp.lang.java.*
Online info & msg boards: www.codeguru.com, www.codeprojects.com
Online info only: www.php.net
---


Igor Buzatovic

unread,
Jan 27, 2003, 9:48:05 AM1/27/03
to
hmm, could be that... thanx..

"Jason Teagle" <ja...@teagster.co.uk> wrote in message
news:UfbZ9.120$Sa1....@newsfep1-gui.server.ntli.net...

Jeff Brown

unread,
Jan 27, 2003, 6:26:32 PM1/27/03
to
You may also want to look at the reload(TreeNode) method of DefaultTreeModel
instead of repaint.


"Igor Buzatovic" <igor.bu...@willevolve.com> wrote in message
news:b138jd$3jk$1...@sunce.iskon.hr...

0 new messages