• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception while implementing drag n drop in java 1.6

 
Fabien Coutel
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have implement dnd functionality using TransferHandler class based on code from
http://www.coderanch.com/t/346509/Swing-AWT-SWT-JFace/java/JTree-drag-drop-inside-one. All works fine when I move nodes to the a parent folder. If I try inserting or or multiples nodes in between other nodes then the tree is updated correctly (i.e the nodes are moved) BUT I get the following exception:
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTreeUI.getDropLineRect(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI.access$1600(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI$Handler.repaintDropLocation(Unknow
n Source)
at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(Unknown Sou
rce)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at javax.swing.JTree.setDropLocation(Unknown Source)
at javax.swing.TransferHandler$DropHandler.setComponentDropLocation(Unkn
own Source)
at javax.swing.TransferHandler$DropHandler.cleanup(Unknown Source)
at javax.swing.TransferHandler$DropHandler.drop(Unknown Source)
at java.awt.dnd.DropTarget.drop(Unknown Source)
at javax.swing.TransferHandler$SwingDropTarget.drop(Unknown Source)
at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(Unknown Sourc
e)
at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEven
t(Unknown Source)
at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(Un
known Source)
at sun.awt.dnd.SunDropTargetEvent.dispatch(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processDropTargetEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
[catch] at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


Any ideas why?

Many Thanks!
 
Zaph Bubblebronx
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

even if this question is almost exactly seven years old, the same issue is also present in Java 1.8.0_101.

I got rid of this NullPointer by overriding firePropertyChange() in my JTree-derived class and filtering the event when the dropLocation is beeing removed.



An alternative would bei to overwrite the BasicTreeUI, but this seemed to be much more complicated in my particular case.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!