Flickering while dragging in Swing

I have such code:

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);
      ...
   }
}

It should draw specified image while dragging. But this image is flickering when I drag it. What should I correct to stop flickering?

Answers


Override the container's paintComponent() method. During drag set the image and location in the container and call normal repaint();


Need Your Help

Database design, avoiding redundant data on HTML forms

database forms database-design

I'm trying to come up with a clean database design for a new project I'm working on. One of the data items I need to store in the database will come from an HTML form:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.