Skip to content

Instantly share code, notes, and snippets.

@cy6erGn0m
Created December 1, 2015 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cy6erGn0m/ba1d95d708c9d6195010 to your computer and use it in GitHub Desktop.
Save cy6erGn0m/ba1d95d708c9d6195010 to your computer and use it in GitHub Desktop.
Drag and drop example
package dnd
import java.awt.*
import java.awt.dnd.*
import javax.swing.*
fun main(args: Array<String>) {
SwingUtilities.invokeAndWait {
val f = JFrame("test")
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.isLocationByPlatform = true
f.preferredSize = Dimension(800, 600)
f.size = Dimension(800, 600)
f.isVisible = true
val dl = object : DropTargetListener {
override fun drop(dtde: DropTargetDropEvent?) {
println("drop")
}
override fun dragOver(dtde: DropTargetDragEvent?) {
println("over")
}
override fun dragExit(dte: DropTargetEvent?) {
println("exit")
}
override fun dropActionChanged(dtde: DropTargetDragEvent?) {
println("changed")
}
override fun dragEnter(dtde: DropTargetDragEvent?) {
println("enter")
}
}
val target = DropTarget(f, DnDConstants.ACTION_COPY_OR_MOVE, dl, true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment