简体   繁体   English

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

[英]can we zoom in zoom out the drawing we draw on the Canvas?

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. 我们有一个古老的Java Swing应用程序(已有10多年的历史了),该应用程序根据实验室数据在JCanvas(JComponent的子类)上绘制了许多圆圈和这些圆圈之间的连接(线)。

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. 我们已经将JCavans放入JScrollPane中,但是滚动图形并不方便。

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. 我们在paintComponent(Graphics g)方法中用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? 在绘制每条圆/线之前,为什么不将x,y和width,height值乘以比例因子? I assume that somewhere your canvas is using a Graphics object to draw each shape? 我假设您的画布某处正在使用Graphics对象绘制每个形状?

You could apply a scaling Transform to the Graphics2D object passed to the paintComponent method. 您可以将缩放Transform应用于传递给paintComponent方法的Graphics2D对象。 You can learn how to use it in the Java 2D programming trail . 您可以在Java 2D 编程指南中学习如何使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM