Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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