Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Link two JPanel's with a line  RSS feed

 
Jeronimo Backes
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?
 
Craig Wood
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 ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!