Can I change the the mouse cursor to a different image when the mouse moves over a specific component in Java?
Created May 4, 2012
Simon Brown All you need to do is add a mouse listener to your component and implement the mouseEntered and mouseExited methods to set and unset the cursor respectively. Here's an example :
myComponent.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent e) { myComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } public void mouseExited(MouseEvent e) { myComponent.setCursor(Cursor.getDefaultCursor()); } });