Java, Drag and Drop: drag image not displaying

Discussion in 'Programming' started by fex, Dec 18, 2010.

  1. #1
    Hello,

    I have set up a Drag and Drop feature in my app using the java.awt.dnd package. It all works well but for the drag image.. it just won't display. Here's the piece of code covering the drag image:

    public class DragListener implements DragGestureListener {
    
        public DragListener(Component component) {
            this.component = component;
        }
    
        public void dragGestureRecognized(DragGestureEvent dge) {
            BufferedImage image = null;
            try {
                image = ImageIO.read(new File("images/bin.png"));
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            dge.startDrag(new Cursor(Cursor.CROSSHAIR_CURSOR), image, new Point(0, 0), new TransferComponent(component), new DragSourceAdapter() {
    
                @Override
                public void dragEnter(DragSourceDragEvent e) {
                }
            });
        }
        private Component component;
    }
    Code (markup):
    Tia
     
    fex, Dec 18, 2010 IP
  2. fancymouj

    fancymouj Peon

    Messages:
    5,019
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i think its a really help full you .. click here
     
    fancymouj, Dec 18, 2010 IP
  3. fex

    fex Peon

    Messages:
    89
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Following your link, under 'Implementing the DragGestureListener Interface', can you tell me what the implementation of the 'drawDragImage(Graphics g)' method would be like? Because that's the key line to the solution... :)
     
    fex, Dec 19, 2010 IP
  4. fex

    fex Peon

    Messages:
    89
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    fex, Dec 21, 2010 IP
  5. haa

    haa Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That bug is 7 years old. You're reading the image, but not drawing it on screen. What are you exactly trying to do?
     
    haa, Dec 22, 2010 IP