I have a JPanel
configured as a dropzone that lets the user drop files in it in order to be analyzed. Now I want to change the background color of that panel when the file is being dragged over it.
How can this be done?
I have a JPanel
configured as a dropzone that lets the user drop files in it in order to be analyzed. Now I want to change the background color of that panel when the file is being dragged over it.
How can this be done?
One way is to add a DropTarget
. Something like this:
yourJpanel.setDropTarget(new DropTarget() {
@Override
public synchronized void drop(DropTargetDropEvent dtde)
{
this.changeToNormal();
//handle the drop ....
}
@Override
public synchronized void dragEnter(DropTargetDragEvent dtde){
//Change JPANEL background...
yourJpanel.setBackground(Color.RED);
}
@Override
public synchronized void dragExit(DropTargetEvent dtde) {
this.changeToNormal();
}
private void changeToNormal() {
//Set background to normal...
yourJpanel.setBackground(Color.WHITE);
}
});