java - JTree DataFlavor issue -


i'm implementing d&d jtree. have written custom transferhandler , created new transferable class. class if easy:

public class treepathtransferable implements transferable{    private static final dataflavor[] flavors = new dataflavor[] {           new dataflavor(treepath[].class,"treepaths")};    private treepath[] data;    public treepathtransferable(treepath[] data) {     super();     this.data = data;   }    public dataflavor[] gettransferdataflavors() {     return flavors;   }    public boolean isdataflavorsupported(dataflavor flavor) {     return flavors[0].equals(flavor);   }    public treepath[] gettransferdata(dataflavor flavor) throws           unsupportedflavorexception, ioexception{     return data;   } } 

if "on drop" call

dtde.gettransferable().gettransferdata(dtde.gettransferable().gettransferdataflavors()[0]) 

i java.io.notserializableexception. if change data-object in treepathtransferable object in following way:

public class treepathtransferable implements transferable{    private static final dataflavor[] flavors = new dataflavor[] {           new dataflavor(object.class,"object")};    private object data;    public treepathtransferable(object data) {     super();     this.data = data;   }    public dataflavor[] gettransferdataflavors() {     return flavors;   }    public boolean isdataflavorsupported(dataflavor flavor) {     return flavors[0].equals(flavor);   }    public object gettransferdata(dataflavor flavor) throws           unsupportedflavorexception, ioexception{     return data;   }  } 

everything works fine. makes no sense me. why difference?

stack trace

note: have replaced non-serializable class xxx. property of subclass of defaultmutabletreenode. subclass not serializable, exception meaningful, why doesn't appear in second case?

java.io.notserializableexception: xxx     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1184)     @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1509)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.writeobject(objectoutputstream.java:348)     @ java.util.hashmap.internalwriteentries(hashmap.java:1777)     @ java.util.hashmap.writeobject(hashmap.java:1354)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ java.io.objectstreamclass.invokewriteobject(objectstreamclass.java:988)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1496)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1509)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.writearray(objectoutputstream.java:1378)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1174)     @ java.io.objectoutputstream.writeobject(objectoutputstream.java:348)     @ javax.swing.tree.defaultmutabletreenode.writeobject(defaultmutabletreenode.java:1287)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ java.io.objectstreamclass.invokewriteobject(objectstreamclass.java:988)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1496)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.writearray(objectoutputstream.java:1378)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1174)     @ java.io.objectoutputstream.access$300(objectoutputstream.java:162)     @ java.io.objectoutputstream$putfieldimpl.writefields(objectoutputstream.java:1707)     @ java.io.objectoutputstream.writefields(objectoutputstream.java:482)     @ java.util.vector.writeobject(vector.java:1077)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ java.io.objectstreamclass.invokewriteobject(objectstreamclass.java:988)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1496)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548)     @ java.io.objectoutputstream.defaultwriteobject(objectoutputstream.java:441)     @ javax.swing.tree.defaultmutabletreenode.writeobject(defaultmutabletreenode.java:1278)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ java.io.objectstreamclass.invokewriteobject(objectstreamclass.java:988)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1496)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548)     @ java.io.objectoutputstream.defaultwriteobject(objectoutputstream.java:441)     @ javax.swing.tree.defaultmutabletreenode.writeobject(defaultmutabletreenode.java:1278)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ java.io.objectstreamclass.invokewriteobject(objectstreamclass.java:988)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1496)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548)     @ java.io.objectoutputstream.defaultwriteobject(objectoutputstream.java:441)     @ javax.swing.tree.defaultmutabletreenode.writeobject(defaultmutabletreenode.java:1278)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ java.io.objectstreamclass.invokewriteobject(objectstreamclass.java:988)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1496)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548)     @ java.io.objectoutputstream.defaultwriteobject(objectoutputstream.java:441)     @ javax.swing.tree.defaultmutabletreenode.writeobject(defaultmutabletreenode.java:1278)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ java.io.objectstreamclass.invokewriteobject(objectstreamclass.java:988)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1496)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548)     @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1509)     @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178)     @ java.io.objectoutputstream.writearray(objectoutputstream.java:1378)     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1174)     @ java.io.objectoutputstream.writeobject(objectoutputstream.java:348)     @ sun.awt.datatransfer.transferableproxy.gettransferdata(transferableproxy.java:83)     @ java.awt.dnd.droptargetcontext$transferableproxy.gettransferdata(droptargetcontext.java:376) 

transferhandler

public class mytreetransferhandler extends transferhandler {     public mytreetransferhandler() {     super();   }    protected transferable createtransferable(jcomponent c) {     transferable t = null;     if(c instanceof jtree) {       jtree tree = (jtree) c;         t = new treepathtransferable(tree.getselectionpaths());         return t;     }     return t;   }    public int getsourceactions(jcomponent c) {     return transferhandler.move;   }    public boolean canimport(jcomponent c, dataflavor[] flavors){     return true;   } } 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -