Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

implement drag drop.  RSS feed

 
shelly kalra
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m using Jdk1.3.1. I want to implement drag and drop within a JList. My list displays images and i need to drag an image from a particular location and drop it at some other location in the same list.
Each element of the list is a Jpanel which contains a Jlabel that displays the image.
I m able to make a template to drag a string from Jlist and drop it on it, but not a Jpanel. Intially i thought that i would, while dragging, get the path of my image and then on recognizing the drop action will redraw my Jlist, but the option didnt work coz my Jlist is ofcourse not acting as a target for StringSelection.I know that i will have to define my own class implementing Transferable for dragging any component, i have tried doing so, but all efforts in vain..
public class FlavorFilter implements Transferable {
private DataFlavor[] flavors =
{
localArrayListFlavor
};
private String path;
public FlavorFilter(String path) {
this.path = path;
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
System.out.println("isDataFlo supp");
return flavor.equals(flavors[0]);
}
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { localArrayListFlavor };
}
public Object getTransferData(DataFlavor flavor) {
Object result = null;
if (isDataFlavorSupported(flavor)) {
result = this.path;
}
return result;
}
}
String text;
Image img;
String localArrayListType = DataFlavor.javaJVMLocalObjectMimeType;

I m not even too sure why im using DataFlavor.javaJVMLocalObjectMimeType..
I m not asking for the exact code but atlest let me know the right approach, if someone has ny idea.
I can post my complete code(though its not complete in ny sense ), if required.
Thanks,
Shelly.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!