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

DnD problem : failed to create native peer

0 views
Skip to first unread message

Guillaume.Rousse

unread,
Apr 27, 2001, 2:03:28 PM4/27/01
to
I have problems with drag & drop in a swing application : i drag tree
content from one JInternalFrame to the JDesktop to create new
JInternalFrames. But every attempt after a successful one fails with this
exception :
Exception occurred during event dispatching:
java.awt.dnd.InvalidDnDOperationException: failed to create native peer at
sun.awt.motif.MDragSourceContextPeer.startDrag(MDragSourceContextPeer.java:90)
at java.awt.dnd.DragSource.startDrag(DragSource.java:265)
at java.awt.dnd.DragSource.startDrag(DragSource.java:358) at
java.awt.dnd.DragGestureEvent.startDrag(DragGestureEvent.java:188)

I use linux and Sun JDK 1.3.1-RC1. With Sun 1.3.0_02 or IBM 1.3.0, result
is the same with just a different error :
message:java.awt.dnd.InvalidDnDOperationException: The operation requested
cannot be performed by the DnD system since it is not in the appropriate
state

The fact that only drag attempts followed by a sucessful drop make the next
one fails makes me think there is something incorrect in my drop code. But
i don't see what :

public void drop(DropTargetDropEvent ev) {
try {
Transferable tr = ev.getTransferable();
if
(tr.isDataFlavorSupported(WidgetSelection.CLASS_DESCRIPTION_FLAVOR)) {
ev.acceptDrop(DnDConstants.ACTION_REFERENCE);
ClassDescription desc = (ClassDescription)
tr.getTransferData(WidgetSelection.CLASS_DESCRIPTION_FLAVOR);
createClassFrame(desc, ev.getLocation());
ev.dropComplete(true);
} else {
ev.rejectDrop();
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
}

}

And here is the WidgetSelection class :
public class WidgetSelection implements Transferable {

public static final DataFlavor CLASS_DESCRIPTION_FLAVOR = new
DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + ";
class=fr.jussieu.snv.lis.osis.access.metadata.ClassDescription",
"Class description"
);
public static final DataFlavor PROPERTY_DESCRIPTION_FLAVOR = new
DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + ";
class=fr.jussieu.snv.lis.osis.access.metadata.PropertyDescription",
"Property description"
);
public static final DataFlavor DOMAIN_OBJECT_FLAVOR = new DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + "; class=java.lang.Object",
"Domain object"
);

private Object selection;
private DataFlavor currentFlavor;

public WidgetSelection(Object selection) {
this.selection = selection;
if (selection instanceof ClassDescription)
currentFlavor = CLASS_DESCRIPTION_FLAVOR;
else if (selection instanceof PropertyDescription)
currentFlavor = PROPERTY_DESCRIPTION_FLAVOR;
else
currentFlavor = DOMAIN_OBJECT_FLAVOR;
}

public Object getTransferData(DataFlavor flavor) throws
UnsupportedFlavorException, IOException {
if (flavor == currentFlavor)
return selection;
else
throw new UnsupportedFlavorException(flavor);
}

public boolean isDataFlavorSupported(DataFlavor flavor) {
if (flavor == currentFlavor)
return true;
else
return false;
}

public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {currentFlavor};
}

}
Any help appreciated !

0 new messages