Java 为小地图创建JComponent的缩放图像
我有一个JavaSwing应用程序,它的主容器是一个大型JPanel。我有更小的JPanel在上面,这构成了一个图表。这些图可能会变大,所以我想实现一个简单的小地图。我会在它周围有一个彩色的矩形,还有一个主图表的缩小版本。它将是只读的。然后,用户可以移动矩形以快速移动图表的各个部分 思考 最好的办法是什么?我对荡秋千还比较陌生,所以很困惑 编辑: 所以我猜我需要做一些像印刷一样的事情Java 为小地图创建JComponent的缩放图像,java,jpanel,Java,Jpanel,我有一个JavaSwing应用程序,它的主容器是一个大型JPanel。我有更小的JPanel在上面,这构成了一个图表。这些图可能会变大,所以我想实现一个简单的小地图。我会在它周围有一个彩色的矩形,还有一个主图表的缩小版本。它将是只读的。然后,用户可以移动矩形以快速移动图表的各个部分 思考 最好的办法是什么?我对荡秋千还比较陌生,所以很困惑 编辑: 所以我猜我需要做一些像印刷一样的事情 // Create a clone of the graphics context. This allows
// Create a clone of the graphics context. This allows us to manipulate
// the graphics context without begin worried about what effects
// it might have once we're finished
Graphics2D g2 = (Graphics2D) g.create();
// Create a new AffineTransformation
AffineTransform at = new AffineTransform();
// Set the scaling
at.scale(scaleFactor, scaleFactor);
// Apply the transformation
g2.transform(at);
// paint the component
comp.paintAll(g2);
// Dispose of the graphics context, freeing up memory and discarding
// our changes
g2.dispose();
实现这一点的方法有很多种。我将从地图区域的缩小图像开始,与“缩放”视图相比,您知道其比例 根据用户“缩放”视图的当前坐标,您需要将这些坐标缩放到小地图比例,并在其表面上生成一个矩形 首先看一看