I would like to change the cursor icon to my customized 32x32 image when a Java application is executing. I looked and searched, those I found are just setting cursor on a JComponent. But I want the cursor changed to my specified icon wherever it goes moving, browsing, and click, as long as the Java application is still running, or you can say program runtime.
Thanks alot.
awt. Cursor class. Create an instance of Cursor using the new operator and pass the cursor type to the Cursor class constructor. We can change Swing's objects ( JLabel , JTextArea , JButton , etc) cursor using the setCursor() method.
Customize Your Mouse on Windows 10Search for and click on “Mouse settings” on your computer via the Start button or the Search bar in your taskbar. In the Window that follows click on “Adjust mouse & cursor size” in the right-side column. The next window will offer options for changing the pointer size and color.
To do so, click the Start button, and then click Control Panel. Click Hardware and Sound, and then under Devices and Printers, click Mouse. In the Mouse Properties box, click on the Pointers and Pointer Options tab, and adjust the options to change the shape and size of your cursor by changing the “scheme”.
Standard cursor image:
setCursor(Cursor.getDefaultCursor());
User defined Image:
Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("icons/handwriting.gif"); Cursor c = toolkit.createCustomCursor(image , new Point(mainPane.getX(), mainPane.getY()), "img"); mainPane.setCursor (c);
You can download a zip containing sample source: HERE
Call Component.setCursor. The class Cursor as a few predefined cursors.
A custom cursor image can be created:
setCursor(Toolkit.getDefaultToolkit().createCustomCursor( new ImageIcon("custom.png").getImage(), new Point(0,0),"custom cursor"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With