我有这样的代码:
public class DpDropTargetListener implements DropTargetListener {
public void dragOver(final DropTargetDragEvent dtde) {
...
if (dtde.getLocation().equals(container.getLastLocation())) {
return;
}
...
Rectangle visRect = container.getVisibleRect();
container.paintImmediately(visRect.x, visRect.y, visRect.width, visRect.height);
//prepare the image to paint, and paint it
...
Graphics2D gr = (Graphics2D) container.getGraphics();
gr.drawImage(container.getDragImage(), AffineTransform.getTranslateInstance(
x, y), null);
...
}
}
拖动时应绘制指定的图像。但是当我拖动它时,这个图像会闪烁。 我该怎么做才能停止闪烁?
答案 0 :(得分:3)
覆盖容器的paintComponent()
方法。在拖动过程中,在容器中设置图像和位置,并调用正常repaint();