LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-14-2010, 12:37 PM   #1
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,204
Blog Entries: 23

Rep: Reputation: 279Reputation: 279Reputation: 279
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)

Tnx!!

Thor
 
Old 03-14-2010, 03:54 PM   #2
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,204
Blog Entries: 23

Original Poster
Rep: Reputation: 279Reputation: 279Reputation: 279
Hi,

Far be it from me to answer my own questions (like having a conversation with myself - I'm not that lonely ) 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
 
  


Reply

Tags
events, java


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New distro needed, pls hlp Thor_2.0 Linux - Desktop 8 01-24-2010 03:58 AM
XS denied - why? pls hlp! Thor_2.0 Programming 2 06-02-2009 09:42 AM
Java and PHP - pls hlp Thor_2.0 Linux - Software 5 04-11-2009 03:14 AM
Alternative JVM - pls hlp Thor_2.0 Programming 4 04-02-2009 01:40 PM
installation probs pls hlp ZINZIN Linux - Newbie 4 03-18-2006 01:58 AM


All times are GMT -5. The time now is 06:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration