public class FileDrop extends java.lang.Object
JPanel myPanel = new JPanel();
new FileDrop( myPanel, new FileDrop.Listener()
{ public void filesDropped( File[] files )
{
// handle file drop
...
} // end filesDropped
}); // end FileDrop.Listener
You can specify the border that will appear when files are being dragged by calling the
constructor with a Border. Only JComponents will show any indication with a
You can turn on some debugging features by passing a PrintStream object (such as
System.out) into the full constructor. A null value will result in no extra
debugging information being output.
I'm releasing this code into the Public Domain. Enjoy.
Original author: Robert Harder, rharder@usa.net
2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
2012-04-12 Stephane Dallogneville -- cleanup, modified for ICY
Modifier and Type | Class and Description |
---|---|
static interface |
FileDrop.FileDropExtListener
Implement this inner interface to listen for when files are dropped.
|
static interface |
FileDrop.FileDropListener
Implement this inner interface to listen for when files are dropped.
|
static class |
FileDrop.TransferableObject |
Constructor and Description |
---|
FileDrop(java.awt.Component c,
boolean recursive,
FileDrop.FileDropListener listener)
Constructor with a default border, debugging optionally turned on
and the option to recursively set drop targets.
|
FileDrop(java.awt.Component c,
javax.swing.border.Border dragBorder,
boolean recursive,
FileDrop.FileDropExtListener listener)
Constructor with a specified border and the option to recursively set drop targets.
|
FileDrop(java.awt.Component c,
javax.swing.border.Border dragBorder,
boolean recursive,
FileDrop.FileDropListener listener)
Constructor with a specified border and the option to recursively set drop targets.
|
FileDrop(java.awt.Component c,
javax.swing.border.Border dragBorder,
FileDrop.FileDropListener listener)
Constructor with a specified border
|
FileDrop(java.awt.Component c,
FileDrop.FileDropListener listener)
Constructor with a default border and debugging optionally turned on.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
remove(java.awt.Component c)
Removes the drag-and-drop hooks from the component and optionally
from the all children.
|
static boolean |
remove(java.io.PrintStream out,
java.awt.Component c,
boolean recursive)
Removes the drag-and-drop hooks from the component and optionally
from the all children.
|
public FileDrop(java.awt.Component c, FileDrop.FileDropListener listener)
c
- Component on which files will be dropped.listener
- Listens for filesDropped.public FileDrop(java.awt.Component c, boolean recursive, FileDrop.FileDropListener listener)
c
- Component on which files will be dropped.recursive
- Recursively set children as drop targets.listener
- Listens for filesDropped.public FileDrop(java.awt.Component c, javax.swing.border.Border dragBorder, FileDrop.FileDropListener listener)
c
- Component on which files will be dropped.dragBorder
- Border to use on JComponent when dragging occurs.listener
- Listens for filesDropped.public FileDrop(java.awt.Component c, javax.swing.border.Border dragBorder, boolean recursive, FileDrop.FileDropListener listener)
c
- Component on which files will be dropped.dragBorder
- Border to use on JComponent when dragging occurs.recursive
- Recursively set children as drop targets.listener
- Listens for filesDropped.public FileDrop(java.awt.Component c, javax.swing.border.Border dragBorder, boolean recursive, FileDrop.FileDropExtListener listener)
c
- Component on which files will be dropped.dragBorder
- Border to use on JComponent when dragging occurs.recursive
- Recursively set children as drop targets.listener
- Listens for filesDropped.public static boolean remove(java.awt.Component c)
Container
.c
- The component to unregister as a drop targetpublic static boolean remove(java.io.PrintStream out, java.awt.Component c, boolean recursive)
out
- Optional PrintStream
for logging drag and drop messagesc
- The component to unregisterrecursive
- Recursively unregister components within a container