0

Say I have two completely unrelated components. The only thing we can assume about them is that they extend JComponent. Is there a way to draw a line between them?

Now remember, we cant assume anything about them. This means, you cant assume they are in the same JFrame, or under the same GlassPane.

user489041
  • 27,916
  • 55
  • 135
  • 204
  • 1
    If they are not in the same frame, then you have massive problems. Using the `GlassPane` or `JXLayer` are the best available solutions. Are they even in the same JVM? – MadProgrammer Feb 19 '15 at 21:15
  • 1
    `you cant assume they are in the same JFrame` well you can't draw lines between different frames so this can't be supported. `or under the same GlassPane` there is only one GlassPane per frame so if you want to draw the line they must be under the same glass pane (if the glass pane is visible). – camickr Feb 19 '15 at 21:16
  • It would help if you provided some form of screen-shot with overlay graphics of what you're trying to achieve. – aioobe Feb 19 '15 at 21:18
  • Yes, a good example would be two components in two different JFrames. Drawing a line that connects these two components – user489041 Feb 19 '15 at 21:18
  • @camickr Is it possible to have some opaque panel of some kind that covers the whole screen you can draw this line onto somehow? It still shows everything under it, but can be used to draw the line – user489041 Feb 19 '15 at 21:22
  • if you want an opaque window you can frame.setBackground(new Color(0,0,0,0)); in that window you can add a panel and then draw on it – crAlexander Feb 19 '15 at 21:24
  • Actually you want a "transparent" frame (not "opaque") as demonstrated by crAlex. It might work if you can somehow make this frame "always on top" so that it gets painted after the other frames. If you have a reference to the components in question then you can use the `Component.getLocationOnScreen()` method to get the coordinates and then draw a line. – camickr Feb 19 '15 at 21:27
  • Then you have issues of overlap. Even if the transparent frame is set to always on top, some OS will still position windows above it... – MadProgrammer Feb 19 '15 at 21:35
  • It would heap less trouble to create a tri-dimensional world view with some other tools (such as Java 3D) instead of trying it with standard swing – alainlompo Feb 19 '15 at 22:41
  • Possible [approach](http://stackoverflow.com/q/3951383/230513). – trashgod Feb 20 '15 at 11:11

0 Answers0