public class FileDrop
extends java.lang.Object
To use this class, construct a new FileDrop by passing it the target component and a Listener to receive notification when file(s) have been dropped. Here is an example:
JPanel myPanel = new JPanel(); new FileDrop( myPanel, new FileDrop.Listener() { public void filesDropped( java.io.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 javax.swing.border.Border. Only JComponents will show any indication with a border.
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, rob@iharder.net
Additional support:
Modifier and Type | Class and Description |
---|---|
static interface |
FileDrop.Listener
Implement this inner interface to listen for when files are dropped.
|
Constructor and Description |
---|
FileDrop(java.awt.Component c,
FileDrop.Listener listener)
Constructs a
FileDrop with a default light-blue border and, if
c is a Container , recursively sets all
elements contained within as drop targets, though only the top level
container will change borders. |
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.
|
public FileDrop(java.awt.Component c, FileDrop.Listener listener)
FileDrop
with a default light-blue border and, if
c is a Container
, recursively sets all
elements contained within as drop targets, though only the top level
container will change borders.c
- Component on which files will be dropped.listener
- Listens for filesDropped.public static boolean remove(java.awt.Component c)
Container
.c
- The component to unregister as a drop target