Created
May 27, 2011 15:54
-
-
Save fumokmm/995546 to your computer and use it in GitHub Desktop.
Drag & Drop sample for SwingBuilder. for http://d.hatena.ne.jp/fumokmm/20110526/1306421368
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cf. http://www.ne.jp/asahi/hishidama/home/tech/java/swing/DropTarget.html | |
import groovy.swing.SwingBuilder | |
import javax.swing.JFrame | |
import java.awt.dnd.DropTarget | |
import java.awt.dnd.DnDConstants | |
import java.awt.datatransfer.DataFlavor | |
import java.awt.datatransfer.Transferable | |
def swing = new SwingBuilder() | |
def frame = swing.frame(id : 'mainFrame', | |
title: 'Groovy Logo Adder', | |
defaultCloseOperation: JFrame.EXIT_ON_CLOSE, | |
show : true, | |
size : [300, 100]) { | |
label(text: 'Please Drag & Drop your icon file here.') | |
mainFrame.dropTarget = [ | |
drop: { dtde -> | |
def t = dtde.transferable | |
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { | |
dtde.acceptDrop(DnDConstants.ACTION_REFERENCE) | |
t.getTransferData(DataFlavor.javaFileListFlavor).each { | |
println it | |
} | |
} | |
} | |
] as DropTarget | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment