Hi!

How could I change custom cursor size? I was playing with Point(a,b), however the cursor is always 32x32 and it looks horribly. Below you can see my code snippet. Thanks!

Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image imageCrossCursor = toolkit.getImage(BeadToolbarColor.class.getResource("/icons/cross_cursor.png"));
        cross_cursor = toolkit.createCustomCursor(imageCrossCursor, new Point(0,0), "Cross cursor");
panel.setCursor(cross_cursor);

Hey, this is a small class I wrote that has a method for resizing an image

import javax.swing.ImageIcon;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.AlphaComposite;
import javax.swing.JPanel;
import javax.swing.JFrame;

public class ImageResize extends JPanel{

private Image img;
private int width,height;

public ImageResize(){

	ImageIcon ii = new ImageIcon(this.getClass().getResource("alienShip.png"));
	img = ii.getImage();

}

 public void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        drawStockImage(g2d);
        resizeImage(img,g2d);

	}


	public void drawStockImage(Graphics2D g){
		g.drawImage(img,50,50,null);
	}






public void resizeImage(Image i,Graphics2D g){


	int w = i.getWidth(null);
	int h = i.getHeight(null);
	h += h;
	w+=w;
	g.drawImage(i, 70, 70, w, h, null);



}
		public static void main(String[] args){

			JFrame frame = new JFrame("hello");
			frame.add(new ImageResize());
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setVisible(true);
			frame.setSize(800,600);


		}


}

Edited 5 Years Ago by Akill10: n/a

Thank you for your code, but I'm not sure that it can completely solve the problem. Look at this thread: http://www.jguru.com/faq/view.jsp?EID=9958. People say that the image for a custom cursor will be enlarged if it is smaller than 32*32 (pixels). My problem is that I tried to change the image size to 32*32, but still the custom cursor is enlarged and looks really horrible. Any solutions? Thanks!

Edited 5 Years Ago by LianaN: n/a

This article has been dead for over six months. Start a new discussion instead.