Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

error in painting JTree

瀏覽次數:0 次
跳到第一則未讀訊息

Igor Buzatovic

未讀,
2003年1月27日 清晨7:28:262003/1/27
收件者:
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

未讀,
2003年1月27日 上午9:21:442003/1/27
收件者:

"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

未讀,
2003年1月27日 上午9:48:052003/1/27
收件者:
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

未讀,
2003年1月27日 下午6:26:322003/1/27
收件者:
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 則新訊息