5

I want to create a windows 7 loading bar on the taskbar. something like this: This is what I want

I already have a jframe frame where a game loads in it. I want to make the loadingbar show the progress of downloading the cache of the game. The jframe and the downloading are handled in two seperate classes.

When I looked on the web, I found 2 solutions.

  1. SWT: where you can create the loadingbar, but I think you can't combine that with a jframe.

  2. bridj: which is possible to add to jframe, but I don't have any idea how to do this with an existing jframe and the progress and the jframe handled in two different classes.

RuuddR
  • 941
  • 4
  • 13
  • 25
  • 1
    How is this different to the [other question](http://stackoverflow.com/questions/32482999/adding-a-taskbar-loadingbar-to-jframe)? – Andrew Thompson Sep 11 '15 at 14:49
  • @AndrewThompson I had to re-ask because that question was unclear. – RuuddR Sep 11 '15 at 14:50
  • Hello again :-) - Have you tried extending the JFrame, as done in this example: https://github.com/nativelibs4java/BridJ/blob/master/src/main/demos/TaskbarListDemo.java – Eric Leibenguth Sep 11 '15 at 14:51
  • The [example code](https://github.com/nativelibs4java/BridJ/blob/master/src/main/demos/TaskbarListDemo.java) only uses a JFrame because that's easy for a demo. It's the instance of the `ITaskbarList3` object that does all the work and it's trivial to encapsulate that in any other class! – Anya Shenanigans Sep 11 '15 at 14:51
  • You can put a [`ProgressIcon`](http://stackoverflow.com/a/3484251/230513) anywhere you can put an `Icon`. – trashgod Sep 11 '15 at 16:43

1 Answers1

1

There is not a direct solution to what you ask since the progress task bar is OS unique, but trashgod actually got this answered at his post here.
You could create an icon which is affected by your progress & update it, so the taskbar will show what you ask for.
I was inspired, so had to indicate it in case OP didn't catch this. Nice job!

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;
    }
}
Community
  • 1
  • 1
Leet-Falcon
  • 2,107
  • 2
  • 15
  • 23