how to get transparency into cursor?

T

Tim

I am writing an app that has a "palette" of small images(32x32) used
to draw onto the screen. I want the cursor to change to be the
currently selected palette image.
I have that part working, where I run into trouble is when I scale the
image down (zoom out) and make the cursor image smaller. My palette
image gets painted into the cursor at the correct size, but I cannot
make the remaining unused area of the cursor go transparent. Changing
the alpha value of bgColor only changes the remaining area as if it
were viewing the transparent color on a black background.

Any help will be greatly appreciated.

Thanks,
Tim

pnlCursor.setLayout(null);
pnlCursor.setVisible(true);
pnlCursor.setSize(new java.awt.Dimension(intImageSize,intImageSize));
pnlCursor.setBackground(new Color(0,0,0,0));
add(pnlCursor);

imgCursor = pnlCursor.createImage(intImageSize,intImageSize);
gD_c = imgCursor.getGraphics();
g_c = pnlCursor.getGraphics();
pnlCursor.hide();

Color bgColor = new Color(2, 2, 2, 0);
gD_c.setColor(bgColor);
gD_c.fillRect(0, 0, intImageOriginalSize, intImageOriginalSize);
gD_c.drawImage(imgMap,
0,0,
intImageSize,intImageSize,
ForeGroundTile*intImageSize,0,
(ForeGroundTile+1)*intImageSize,intImageSize,
null);

Point hotspot = new Point((intImageSize/2),(intImageSize/2));
pnlGraphics.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(imgCursor,hotspot,"tile"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top