tags:

views:

63

answers:

1

Hi,

Can I drag a JLabel and insert into it a custom object or should I use another component? But I have to use TransferHandler with exportAsDrag.

My code:

final JLabel label1 = new JLabel("Drag here");
Collection<Person> person= new ArrayList<Person>();

//Register transferhandler objects on them label1 transfer itss
//foreground coloer label2 transfer its backgroundcolor

//need here a Transferable to put the object
label1.setTransferHandler(new TransferHandler(....));

label1.addMouseMotionListener(new MouseMotionAdapter() {
    @Override
    public void mouseDragged(MouseEvent e) {
     // TODO Auto-generated method stub
     TransferHandler handler = label1.getTransferHandler();
     handler.exportAsDrag(label1, e, TransferHandler.COPY);
    }
});
+1  A: 

Depends on what you want to drag - the JLabel or just the text.

When you drag something, you create a 'model' of the dragged object, when you drop it, you usually create something new at the destination based on that model.

Andreas_D