Hello all hope you guys can help. I figured out how to change the cursor in my Java application by doing the following:
java.net.URL cursorImgURL = ldr.getResource("ball2.png");
ImageIcon cursorImg = new ImageIcon(cursorImgURL);
//Set Cursor for frame
Point point=new Point(0,0);
Cursor c=Toolkit.getDefaultToolkit().createCustomCursor(cursorImg.getImage(), point,"cursor");
frame.setCursor(c);
This code sets the cursor of the frame on a Mac to the following image: [What cursor looks like on Mac OS X|http://doodletype.com/ball2.png]
However when on Windows it seems to stretch the image like this: [What cursor looks like on Windows|http://doodletype.com/ball_windows.png]
I was wondering if anyone could tell me why it is stretching the cursor and how I could correct this. I want it to display exactly like it looks on Mac OS X (the first image) and not stretched like the second image. Any help would be great. Thanks :)
If you want to try it out here is a little program to display the cursor: You can download the cursor image
here
package cursor;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame {
ImageIcon cursorImg = new ImageIcon("");
Cursor c;
public static void main(String[] args) {
new Main();
}
public Main() {
JTextField field = new JTextField("");
field.setText(JOptionPane.showInputDialog(this,"Enter the full filepath for the cursor image","Cursor image?",JOptionPane.QUESTION_MESSAGE));
if(!field.getText().equals("")) {
cursorImg = new ImageIcon(field.getText());
}
else {
System.exit(0);
}
File image = new File(field.getText());
if(!image.exists()) {
JOptionPane.showMessageDialog(this, "Image file does not exist, please check the file path and try again.","Warning",JOptionPane.WARNING_MESSAGE);
System.exit(0);
}
//Create cursor
Point point=new Point(0,0);
c=Toolkit.getDefaultToolkit().createCustomCursor(cursorImg.getImage(),point,"cursor");
setCursor(c);
setSize(500,500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}