如何在任务栏上制作Windows 7加载栏

Ruu*_*ddR 5 java swing

我想在任务栏上创建一个 Windows 7 加载栏。像这样的东西: 这就是我要的

我已经有一个 jframe 框架,可以在其中加载游戏。我想让loadingbar显示下载游戏缓存的进度。jframe 和下载在两个单独的类中处理。

当我查看网络时,我发现了2个解决方案。

  1. SWT:您可以在其中创建加载栏,但我认为您不能将其与 jframe 结合起来。

  2. Bridj:可以添加到 jframe 中,但我不知道如何使用现有的 jframe 以及在两个不同的类中处理的进度和 jframe 来执行此操作。

Lee*_*con 1

对于您所问的问题,没有直接的解决方案,因为进度任务栏是操作系统独有的,但trashgod实际上在他的帖子得到了答案。
您可以创建一个受进度影响的图标并更新它,这样任务栏就会显示您所要求的内容。
我受到了启发,所以必须指出,以防 OP 没有注意到这一点。不错的工作!

private static class ProgressIcon implements Icon {

    private static final int H = 16;
    private static final int W = 3 * H;
    private Color color;
    private int w;

    public ProgressIcon(Color color) {
        this.color = color;
    }

    public void update(int i) {
        w = i % W;
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.setColor(color);
        g.fillRect(x, y, w, H);
    }

    public int getIconWidth() {
        return W;
    }

    public int getIconHeight() {
        return H;
    }
}
Run Code Online (Sandbox Code Playgroud)