This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Link two JPanel's with a line

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to display two or more JPanel's in a JFrame, in random positions, and display a line linking them? The line should end at the center of the JPanel, but can't appear over the panel.

To be brief: It should look like a diagram of movable and resizable JPanel's.

A resizer and mover of components I've already made. The only problem is to display the links between them as lines.

Anyone has any idea of how to do that?
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Draw the line in the container that is parent to the panels. If it is a content pane or a JPanel you can override the 'paintComponent' method. To get the end points for the lines you can try:
 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply man. I already did that, but I was doing that with the paint() method. But here goes the worst problem: How to move the panels and update the line?

Don't be scared with the size of the code here. It is just to allow you (and anybody else) to run and test, and then be able to give a answer. You will be interested just in the PanelTest class, and only in the minor methods. I just need a answer to that:

How can I show the line moving with the panels when one of them is dragged?




PS: the code posted here can be used and modified as you wish. The resizer class needed some hacks to work right

[ August 09, 2005: Message edited by: Jer�nimo Backes ]
[ August 09, 2005: Message edited by: Jer�nimo Backes ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know, there is a library called JGraph that already does all this for you. If you are doing this to learn then great, but if you need something that already works, go with JGraph.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Gregg Bolinger:
You know, there is a library called JGraph that already does all this for you. If you are doing this to learn then great, but if you need something that already works, go with JGraph.



Yep, I know. But the manual costs 50 bucks. And you can't add JComponents to a graph of JGraph. I need to display a graph in a canvas, and every node MUST display a JTree (with information about the node), a JComboBox and a JToggleButton.

I don't know much of JGraph, but I'm almost certain that you can't do this sort of thing with it.
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!