5

I want to add a taskbar icon for my running lwjgl process on Windows 7.

Display.setIcon changes successfully the icon in the topleft of the window, but not in the taskbar.

What do to?

My code, something like:

ArrayList<ByteBuffer> byteBuffers = new ArrayList<ByteBuffer>();
byteBuffers.add( ImageHelper.loadImageAsIconImage("stickmanicon32x32.png") );
byteBuffers.add( ImageHelper.loadImageAsIconImage("stickmanicon16x16.png") );
System.out.println( "taskbaricon result: " + Display.setIcon(byteBuffers.toArray(new ByteBuffer[]{})) );

I tried adding a 40x40 image too, but no change.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Hugh Perkins
  • 7,975
  • 7
  • 63
  • 71
  • 1
    I believe the problem with the above is your toArray call. You need to allocate a ByteBuffer array of length 2 to hold you 2 buffers. You're creating an empty array: "new ByteBuffer[] { }" should be "new ByteBuffer[2]" – thomas88wp Aug 26 '13 at 22:40

3 Answers3

5

This code worked just fine for me. No need of extra libs.

ByteBuffer[] list = new ByteBuffer[2];
list[0] = createBuffer(ImageIO.read(new File("src/Images/Tests/icon16.png")));
list[1] = createBuffer(ImageIO.read(new File("src/Images/Tests/icon32.png")));
Display.setIcon(list);
Baz
  • 36,440
  • 11
  • 68
  • 94
MxR
  • 150
  • 3
  • 10
  • 2
    That looks the same as my code. Did you try this on Windows 7? – Hugh Perkins Sep 29 '12 at 14:44
  • Ok, I don't have time to check right now. I will mark the answer as accepted, since no-one came up with anything better. It seems to me there are two possibilities: 1. there used to be a bug, and now there is not, it's fixed in a more recent version of lwjgl 2. you're using icon sizes 16 and 32, whereas I was using 32 and 16, ie the order is different. – Hugh Perkins Oct 31 '12 at 04:13
2

This is what i found out after messing around after a few hours.

I used the slick-util lib.

Display.setIcon(new ByteBuffer[] {
                    new ImageIOImageData().imageToByteBuffer(ImageIO.read(new File("res/game/gameIcon.png")), false, false, null),
                    new ImageIOImageData().imageToByteBuffer(ImageIO.read(new File("res/game/gameIcon.png")), false, false, null)
                    });
Tyler Bucher
  • 103
  • 3
  • 8
2

You should have a look at J7Goodies a Java library that provides many Windows 7 features.

torn
  • 609
  • 6
  • 7