Drag and Drop example

Hi There,
I’m trying to implement normal Drag and Drop behaviour by deriving my components from DragAndDropContainer and Component base classes.

The problem i encounter is that every time i call startDragging the following happends…
it fails while trying to cast itsself to a Component (see code snippet below).

does anyone has a clue what i’m doing wrong and or has an example of a working Drag and Drop application…
any help is greatly appreciated…

void DragAndDropContainer::startDragging (const String& sourceDescription,
Component* sourceComponent,
Image* im)
if (dragImageComponent != 0)
if (im != 0)
delete im;

	Component* const thisComp = dynamic_cast<Component*> (this);

I’m a bit confused on the whole drag and drop operations myself. Is there any example code that uses the drag and drop functionality between two Juce dialogs? Cheers

first derive your main window from DragAndDropContainer.
next add the following to the mouseDrag method of the component you want to drag:

DragAndDropContainer* dragC = DragAndDropContainer::findParentContainerFor(this); if (!dragC.isDragAndDropActive) { dragC.startDragging("description string",this); }
then derive any component that you want to be able to drop something on from DragAndDropTarget and implement all the required methods.

1 Like