Skip to content
Advertisement

Implementing Cursor in Java with some Transparency

I have a 35×40 px. png image I want to use as a custom cursor in a Swing application. The image has a glow so contains alpha transparency values. Problem is when I attempt to use the conventional method of using the Toolkit to generate the custom cursor I get black pixels where alpha transparency values should be.

Here is the image I am using for a cursor: https://dl.dropbox.com/u/1186703/cursor.png

Here is my code:

JavaScript

Here is the current result:

result

Edit it seems that this method does not work well cross platform, for instance Windows LAF doesn’t support semi-transparency. I am therefore looking for any solution to get this to work on windows, assuming this implementation does work on Mac OSX, i can just specify in code which implementation to use based on which operating system the app is running on.

Advertisement

Answer

The problem your having is to do with the Cursor class which (under Windows) doesn’t take into account the transparency values of the image

This is, by no means, a “real” solution, but is more about “fudging” the result…

JavaScript

I got the idea for here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement