Custom Cursor Issue

I am creating a custom cursor using the following code:


   public void fillCursor()
   {
      cursorImages = new Image[1];
      cursorImages[0] = Toolkit.getDefaultToolkit().getImage("bin/gui/cursor.gif");
   }
   public static void setCursor(int state)
   {
      canvas.setCursor(canvas.getToolkit().createCustomCursor(cursorImages[state], new Point(0,0), "Cursor"));         
   }

It does indeed change my cursor, but I’m having a very strange problem, the color of my image is messed up. I have made sure that the canvas itself draws the image correctly, so I’m not really sure what’s wrong. Any ideas?

Try changing “canvas.getToolkit()” to “Toolkit.getDefaultToolkit()”. I don’t think it will really matter, but it seems strange that you’re getting a toolkit from the canvas.

Normally, I would think that it’s just a problem with the .gif file because .gif doesn’t usually seem to store colors quite right. But that seems unlikely if it draws properly to the canvas when it’s not a cursor.

Yeah, .gifs are a pain color-wise, but I’m sure its not the image because
g.drawImage(cursorImages[0],0,0,null);
works fine.

The old test file I had for custom cursor also appears to have problems displaying color correctly :S, are cursors limited to certain colors?

Oh, while I’m at it. I want to make my gui holders display a dynamic bg image and border. By dynamic I mean that it takes two base images and tiles them appropriately and, hopefully, stores that as a simple image. Is this possible, and if so, where do I start?

Thanks!

What version of the Java runtime are you using?

I seem to remember there used to be a bug with the gif decoder when operating on 4bpp gifs, maybe it’s still there…

I’m using Java 1.6 on Ubuntu

Which Java 1.6? The Sun JDK or the OpenJDK?

Sun’s, I believe.

Switch off your cursor using Toolkit.getDefaultToolkit().createCustomCursor(getToolkit().createImage(""),
new Point(0,0), “”);

Then, use a MouseMotionListener to remember where your mouse is.

Next, draw the cursor as an Image in the paint(Graphics g) method, at the co-ordinates remembered by your MouseMotionListener.

creating a custom cursor using the toolkit adds extra things, I dunno what…