Results 1 to 3 of 3
Thread: DnD problem
- 02-13-2010, 02:01 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 14
- Rep Power
- 0
DnD problem
Ho guys i want just your idea about the following problem:
i have a jlabel than implements a droptarget listener...it makes some operation when i drop an image inside(this image is dragged from another component)...
I would to limitate the drop area inside the component without(or with less) modify the droptarget method. I create a polygon inside jlabel and i would that droplistener calls drop methods only when mouse goes inside polygon area...any idea? Thx you in advance guys...
- 02-15-2010, 12:24 AM #2
I made up a test app to find out.
Here's some of the drop target listener code.
Java Code:class DropLabel extends JLabel { DropTarget dropTarget; DropTargetListener targetListener; int actions = DnDConstants.ACTION_COPY; Polygon polygon; public DropLabel(ImageIcon icon) { super(icon); targetListener = new TargetListener(); // component, actions, DropTargetListener, accepting dropTarget = new DropTarget(this, actions, targetListener, true); } private class TargetListener implements DropTargetListener { ... public void dragOver(DropTargetDragEvent dtde) { Point loc = dtde.getLocation(); // Drop point must be over polygon. if(!isDragOK(dtde) || !polygon.contains(loc)) { dtde.rejectDrag(); return; } dtde.acceptDrag(dtde.getDropAction()); } public void drop(DropTargetDropEvent dtde) { // Check for congruity of actions. ... // Recover image from transferable data. BufferedImage image = ... // Check drop location is over polygon. Point loc = dtde.getLocation(); if(!polygon.contains(loc)) { dtde.dropComplete(false); return; } dtde.dropComplete(true); setIcon(new ImageIcon(image)); } ... } ... }
- 02-16-2010, 06:58 PM #3
Member
- Join Date
- Jan 2010
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
simple line problem / for loop problem
By helpisontheway in forum New To JavaReplies: 1Last Post: 11-17-2009, 06:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks