• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic creation of transparent cursor  RSS feed

 
Lee Orsino
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know its possible to create a transparent cursor from a GIF image. But is it possible to create one dynamically? I'm trying to do it this way (see code below) but the cursor turns out completely blank, as if I had turned it off.

public void setMyCursor(int width, height)
{
int pix[] = new int[width * height];

for (int i = 0; i < pix.length; i++)
{
if (i % 3 == 0) pix[i] = 0x00ff0000;
}

Image img = createImage(new MemoryImageSource(width, height, pix, 0, width));
Cursor myCursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(5, 5), "myCursor");
setCursor(myCursor);
}
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should work fine if you just use 0xffff0000 instead of 0x00ff0000.

Or you could do it with a BufferedImage instead of a MemoryImageSource:
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How come sometimes code blocks come out in teeny type
but other times not? (See, for example, this thread.

Also, how come there isn't a way to preview a post/reply
before committing it?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!