• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Link two JPanel's with a line

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Men call me Jim. Women look past me to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic