2014-08-29 47 views

回答

0

顯然,ToolbarUI中的paintDragWindow做到了這一點。

我用這個代碼創建我的工具欄的圖像作爲浮動img。

@Override 
protected void paintDragWindow(Graphics g) { 
    BufferedImage img = getScreenShot(this.toolBar); 
    g.drawImage(img, 0, 0, null); 
    g.setColor(dragWindow.getBorderColor()); 

    g.drawRect(0, 0, toolBar.getWidth() - 1, toolBar.getHeight() - 1); 
    System.out.println("paint drag window"); 
} 

public static BufferedImage getScreenShot(Component component) { 

    BufferedImage image = new BufferedImage(component.getWidth(), 
      component.getHeight(), BufferedImage.TYPE_INT_RGB); 
    // call the Component's paint method, using 
    // the Graphics object of the image. 
    component.paint(image.getGraphics()); // alternately use .printAll(..) 
    return image; 
}