【问题标题】:How to change JToolbars floating image如何更改 JToolbars 浮动图像
【发布时间】:2014-08-29 16:18:35
【问题描述】:

有没有一种简单的方法来更改 JToolbars 浮动图像,如传输处理程序中的拖动图像,而无需编写自己的传输处理程序?

【问题讨论】:

    标签: image swing floating jtoolbar


    【解决方案1】:

    显然 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-07
      • 1970-01-01
      • 1970-01-01
      • 2013-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多