2012-07-20 46 views
0

我剛剛在包含透明部分的JPanel中產生工件問題。 我的JPanel覆蓋的paintComponent()方法:Java:使用alpha繪畫重繪文物

protected void paintComponent(Graphics g) { 
    g2d = (Graphics2D) g; 
    drawMyAplhaImage(g2d); 
} 

Repaint Artifacts

正如你所看到的,在JPanel中繪製的圖像比的JPanel本身有點小。

回答

0

解決方法是重新繪製父組件。

爲了節省資源,我只是重新繪製JPanel的區域。

新的paintComponent()方法:

protected void paintComponent(Graphics g) { 
    g2d = (Graphics2D) g; 
    getParent().repaint(getX(), getY(), getWidth(), getHeight()); 
    drawMyAplhaImage(g2d); 
}