Swing Question (Drag and Drop??)

Posted on 2001-06-12
Last Modified: 2013-12-14
I'm wondering if anyone could tell me (a) if the following is possible in swing and (b) if so, how you'd implement it please ! :)

I'm wondering if I could have the following situation,
a JFrame that contains 2 scroll panes,
One on the left, one on the right.
In each scroll pane there is a JTree.
I'd like to create the visual "mapping" between nodes of these two seperate trees. I.E. You click on a node in the left jtree, and drag a line to a another node in the right jtree. When you "let go" a line permenantly appears between the 2 nodes in the 2 different trees. Can this be done ??? the drawing of lines between 2 seperate components ?? Personally, I don't think it can be done in swing at the moment, but ppl around me are saying "yeah java drag and drop can do that" without giving me any details :) Sun's drag and drop tutorial is not written yet - and the javaworld one mentions nothing like the behaviour I've described above.

Any opinions/insights ????

Also as a side note ...... The default behaviour of a jtree is that it expands left-to-right, can you change it so that it expands right-to-left ??? ie "backwards".

any help/opinions greatly appreciated,
Question by:somadude
  • 3
  • 2
  • 2
  • +2
LVL 35

Accepted Solution

TimYates earned 200 total points
ID: 6180804
I think for the line drawing you will have to use the classpane on your main window

try having a look at:


Is quite a nice page for explanation...

Now drag and drop...  try


Hope this helps...  Sorry I havent really supplied you with any code, but these links should explain stuff better than I could...

One thing to watch out for drag and drop...  It seems to work differently on Linux/Solaris/Windows (Linux bein the worst) so you might need to do a bit of tweaking and have access to all these systems to ensure it works fully :-)

Have fun!!

Good Luck!!


Expert Comment

ID: 6181261
Hi ,
I have a word document write by a university teacher.
Maybe that could be useful to you.

Please e-mail me ( sending this to you.

LVL 35

Expert Comment

ID: 6181278
Instead of posting this as an answer, wouldn't it have been best posting a comment?  Also, this doesn't help anyone in the future who buys this question...

Could you post the most important points/code as a comment?

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

LVL 92

Expert Comment

ID: 6183826

Have a look at the ee guidlines for comments and answers, and then have a good hard look at your 'proposed answer'.
If you have an answer then post it, otherwise ...

Author Comment

ID: 6184985
Well no sign of the word doc, so for now it's more a comment than answer, cheers.

Expert Comment

ID: 6185135
Sorry for posting like answer.
My fault. In the future will not happend again.
Sorry again.


LVL 92

Expert Comment

ID: 6188880
Apology accepted :)
LVL 35

Expert Comment

ID: 6190104
From me too :-)
LVL 14

Expert Comment

ID: 9027578
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

[points to TimYates]

Please leave any comments here within the next seven days.
EE Cleanup Volunteer
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ArrayIndexOutOfBoundException 9 83
java 8 lambda expresssions exception handling 3 91
couple of eclipse 5 37
Facing this issue for maven proxy setting 2 12
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question