I have a 35x40 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:
public static void main(String[] args) throws IOException {
new Sandbox().gui();
}
private Cursor cursor;
private Toolkit kit;
private Image cursorImage;
public void gui() {
kit = Toolkit.getDefaultToolkit();
cursorImage = kit.createImage(getClass().getResource(
"/aurora/V1/resources/cursor.png"));
cursor = Toolkit.getDefaultToolkit().createCustomCursor(
cursorImage, new Point(0, 0), "CustomCursor");
setSize(800, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
setCursor(cursor);
}
Here is the current 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.
HCURSOR
with the window. – BerlindaWNDCLASSEX
viaSetClassLong
but it has no effect on cursor over JFrame. Yet this approach works perfectly in Win32 API. – Berlinda