我遇到如图所示的问题
我的添加过程如下:
JFrame -> View 面板 -> JTabbedPane -> JPanel(我的 Canvas )
我在paintComponent中绘制绘图,并在最后调用revalidate()。非常感谢您的帮助!
编辑:
paint组件代码
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
//Obtain document size
double width = model.getWidth();
double height = model.getHeight();
canvasBounds = new Rectangle2D.Double(0, 0, width, height);
g2d.setColor(Color.WHITE);
g2d.fill(canvasBounds);
Dimension size = new Dimension();
size.setSize(canvasBounds.getWidth() * zoomFactor, canvasBounds.getHeight() * zoomFactor);
this.setPreferredSize(size);
g2d.setClip(canvasBounds);
List<DrawableShape> svgShapes = model.getDrawableShapes();
for(DrawableShape shape : shapeList) {
shape.draw(g2d);
}
revalidate();
}
最佳答案
看起来有些东西不遵守您的剪辑
的范围。也许它在 shape.draw()
方法中被更改?
为什么不尝试创建一个新的 Graphics 对象来传递给 shape.draw()
,而不是 setClip()
。像这样的事情...
Graphics2D newG = (Graphics2D)g.create(0, 0, width, height);
然后将代码更改为...
shape.draw(newG);
关于java - JScrollPane 中的 Jpanel,在滚动条上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10620883/