我们可以放大缩小在画布上绘制的图形吗?

发布于 2024-09-24 15:04:33 字数 332 浏览 0 评论 0原文

我们有一个旧的(超过 10 年历史)Java Swing 应用程序,它根据实验室数据在 JCanvas(JComponent 的子类)上绘制大量圆圈以及这些圆圈之间的连接(线)。

由于数据越来越大,我们现在无法显示整个绘图。我们已将 JCavans 放入 JScrollPane 中,但滚动绘图不方便。

我们可以为其添加放大缩小吗?如果是,怎么办?我知道我们可以缩放图像,但是 Canvas 上的绘图是图像吗?

谢谢,

编辑:

我们在 paintComponent(Graphics g) 方法中绘制这些圆圈并使用 Graphics 绘制线条。

We have an old (more than 10yrs old) Java Swing applicatin which draws lots of circles and connections (lines) between those circles on a JCanvas (a subclass of JComponent) based on lab data.

Because the data becames bigger and bigger, we cannot display the entire drawing now. We have put the JCavans into a JScrollPane but it is not convenience to scroll the drawing.

Can we add zoom in zoom out for it? if yes, how? I know we can zoom image but the drawing on Canvas is an image?

thanks,

EDIT:

we draw those circles and line with Graphics within paintComponent(Graphics g) method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

じ违心 2024-10-01 15:04:33

您可以对传递给 paintComponent 方法的 Graphics2D 对象应用缩放 Transform。您可以在 Java 2D 编程教程中了解如何使用它。

You could apply a scaling Transform to the Graphics2D object passed to the paintComponent method. You can learn how to use it in the Java 2D programming trail.

尽揽少女心 2024-10-01 15:04:33

如果不了解有关您的应用程序的任何信息,就很难提供有用的建议(添加代码片段或更好的精简示例应用程序将有助于展示事物的绘制方式),但我会尝试一下:

为什么不呢?在绘制每个圆/线之前,将 x、y 和宽度、高度值乘以比例因子?我假设您的画布在某个地方使用 Graphics 对象来绘制每个形状?

Without knowing anything about your application it's hard to provide useful advice (adding a code snippet or better yet a cutdown example app would be helpful to show how things are being drawn), but I'll give it a shot:

Why don't you multiply the x,y and width,height values by a scaling factor before you draw each circle/line? I assume that somewhere your canvas is using a Graphics object to draw each shape?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文