Java:使用alpha绘画重绘文物
问题描述:
我刚刚在包含透明部分的JPanel中产生工件问题。 我的JPanel覆盖的paintComponent()方法:Java:使用alpha绘画重绘文物
protected void paintComponent(Graphics g) {
g2d = (Graphics2D) g;
drawMyAplhaImage(g2d);
}
正如你所看到的,在JPanel中绘制的图像比的JPanel本身有点小。
答
解决方法是重新绘制父组件。
为了节省资源,我只是重新绘制JPanel的区域。
新的paintComponent()方法:
protected void paintComponent(Graphics g) {
g2d = (Graphics2D) g;
getParent().repaint(getX(), getY(), getWidth(), getHeight());
drawMyAplhaImage(g2d);
}