I'm new in Java and I have a problem trying set an image to the cursor. I'm using a BufferedImage
and Graphics.drawImage
but it is only drawing a color of the image and not the full png image.
Here is my code:
/*The images List*/
iconsBet.add(ImageIO.read(getClass().getResource("/resources/ChipType"+ String.valueOf(maxChipBet+1) +".png")));
/*The images List*/
BufferedImage output = new BufferedImage(iconsBet.get(0).getWidth(), iconsBet.get(0).getHeight(), BufferedImage.TYPE_INT_ARGB );
Graphics graphicsCursorIcon = output.getGraphics();
int count = 0;
for(BufferedImage icon : iconsBet)
{
graphicsCursorIcon.drawImage(icon, 0, count*10, null);
count++;
}
graphicsCursorIcon.dispose();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Cursor c = toolkit.createCustomCursor(output , new Point(mainPanel.getX(), mainPanel.getY()), "img");
mainPanel.setCursor(c);
The image: This is one image from the group of images that I'm using
The program only draw a red circle and not the png image.
I already tried use all the BufferedImage
types, but yet doesn't work.
Could you please help me with this? What do I need to do to make it work?