在 1 个 JPanel 中的 2 个图像之间绘图
我想在 2 个 JScrollPanes 之间绘制线条(第一个滚动窗格在左侧,第二个滚动窗格在右侧)。这些 JScrollPanes
包含图像。我想在这两个图像之间画线(使用一些图层,使用一些技巧等)。我尝试用不同的方式来做,但失败了。是否可以? (如果没有,我将不得不在一个 JScrollPane
中制作 2 个图像,这不会很好)。
编辑
我想在两个图像之间绘制 - 通过组件 - 从图像中获取一些点并在它们之间绘制线条。对于问题表述不当,我深表歉意。
I want to draw the lines between 2 JScrollPanes
(first scroll pane on the left side, second on the right). These JScrollPanes
contain images. I want to draw lines between these 2 images (use some layers, use some trick etc.). I tried do it different ways, but i failed. Is it possible? (if not, i will have to make 2 images in one JScrollPane
and it won't be nice).
EDIT
I want to draw between 2 images - throught components - get some points from images and draw lines between them. I apologize for poorly formulated question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了实现这一目标,我相信您需要使用
Glass Pane
。Glass Pane
位于JRootPane
中所有内容的顶部,并填充整个视图。这个特殊的位置允许两种不同的功能:我相信第二个功能可以解决您的问题。以下是一个示例实现,您可以稍后对其进行定制以满足您自己的需求。请注意,我遗漏了许多有关
Glass Pane
的细节,您需要自己研究。代码
输出
说明
中,我单击每个 JLabel 内的任意两个点,然后绘制一条连接线。
In order to accomplish this, I believe you'll need to make use of the
Glass Pane
. TheGlass Pane
sits on top of everything in theJRootPane
and fills the entire view. This particular position allows two distinct capabilities:I believe your question is addressed by the second capability. The following is an example implementation, which you can later tailor to meet your own needs. Note that I've left out a lot of detail with regard to
Glass Pane
that you'll need to research on your own.CODE
OUTPUT
EXPLANATION
In this example, I clicked two arbitrary points within each
JLabel
, and then drew a connecting line.这应该是很有可能的。您将需要创建一个可识别两个垂直滚动条的自定义组件。它应该将自身作为
AdjustmentListener
添加到每个滚动条,以便检测更改并重新绘制两者之间的线条。看:
addAdjustmentListener API 中的方法
This should be very possible. You will need to create a custom component that is aware of both vertical ScrollBars. It should add itself as an
AdjustmentListener
to each scroll bar in order to detect changes and repaint the lines between the two.See:
addAdjustmentListener method in the API
你可以用这个
http://java-sl.com/connector.html
作为此类代码的示例。
You can use this
http://java-sl.com/connector.html
as an example of such code.