如何在任务栏上创建一个Windows 7加载栏

时间:2015-09-11 14:39:39

标签: java swing

我想在任务栏上创建一个Windows 7加载栏。这样的事情: This is what I want

我已经拥有一个游戏加载的jframe框架。 我想让loadingbar显示下载游戏缓存的进度。 jframe和下载分为两个单独的类。

当我在网上看到时,我找到了2个解决方案。

  1. SWT:您可以在哪里创建加载栏,但我认为您无法将其与jframe结合使用。

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

1 个答案:

答案 0 :(得分:0)

由于进度任务栏是操作系统唯一的,因此没有直接的解决方案,但是 trashgod 实际上已在帖子here上回答了问题。
您可以创建一个受进度和影响的图标。更新它,因此任务栏将显示您要求的内容 我受到启发,所以不得不指出它,以防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;
    }
}