LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   JTexrField needs to respond to drop - pls hlp (http://www.linuxquestions.org/questions/programming-9/jtexrfield-needs-to-respond-to-drop-pls-hlp-795349/)

Thor_2.0 03-14-2010 12:37 PM

JTexrField needs to respond to drop - pls hlp
 
Hi,

So, DnD is cool - and in Java, it works. Just set the component where the drag starts to allow that:

Quote:

tblMain.setDragEnabled(true);
and - yes - the rest pretty much runs itself. I have a JTextField that happily takes the drop from the JTable (be it the whole row - I'm not there yet, still working on that)...but does not raise any events.

I'd like the JTextField to raise an event:
- cleaning up the received data, now it gets the raw stuff, and I need an ID from that string
- starting up another void() with the received ID

I read the tutorials but - for blisters - cannot see the "light", please shed some (light, that is) :D

Tnx!!

Thor

Thor_2.0 03-14-2010 03:54 PM

Hi,

Far be it from me to answer my own questions (like having a conversation with myself - I'm not that lonely :D ) but, I've licked it - I think.

Drag-n-Drop in Java, in a few lines:

- Set up the GUI
- mark the component that needs to "export" data ie where the drag begins with:
Quote:

someDragComponent.setDragEnabled(true);
- add a DropTarget to the component to receive (and of course do something with) the dropped data, use this snippet:

Quote:

someDropComponent.setDropTarget(new DropTarget()
{
@Override
public void dragEnter(DropTargetDragEvent dtde) {
// TODO Add code here

}

@Override
public void dragExit(DropTargetEvent dte) {
// TODO Add code here

}

@Override
public void dragOver(DropTargetDragEvent dtde) {
// TODO Add code here

}

@Override
public void drop(DropTargetDropEvent dtde) {
// TODO Add code here
// this is where the component "rattles the cage", so
// drop some (sensible) code right here

}

@Override
public void dropActionChanged(DropTargetDragEvent dtde) {
// TODO Add code here

}

});
That should do it, tested this on a JTextField and it works.

Hope to have helped - for once...

Wellness to all out there - in WonderLand, where they use Linux.

I'm off to bed...

Thor


All times are GMT -5. The time now is 09:57 AM.