I'm working on learning swing graphics, and I wanted to try to change the cursor color in java. So I downloaded a gif file of some golden stars to try to use for my cursor, but when I added the image as an ImageIcon, it turned the stars' colors to black.
EDIT: Changed grammar
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class stuff {
public static void main (String[] args)
{
JFrame frame = new JFrame("FRAME");
JPanel lpanel = new JPanel();
frame.setContentPane(lpanel);
ImageIcon goldStar = new ImageIcon("./res/goldStar.gif");
JLabel gs = new JLabel(goldStar);
lpanel.add(gs);
goldStar = new ImageIcon(goldStar.getImage().getScaledInstance((int)(goldStar.getIconWidth()/13), (int)(goldStar.getIconHeight()/13), Image.SCALE_SMOOTH));
lpanel.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(goldStar.getImage(),new Point(0,0), "custom cursor"));
//I think these two lines are creating the problem.
lpanel.setPreferredSize(new Dimension(1600,900));
frame.setVisible(true);
frame.pack();
}
}
I looked through some of the methods for cursor, but I didn't find anything that could help me out.
This is the picture I'm trying to integrate as my mouse cursor: