Custom Cursor java

风流意气都作罢 提交于 2019-12-11 02:15:29

问题


So my issue is that on Saturday I made a custom frame in Java and I made it so the user can move the frame. I got that working. Now my question is that I have a label which gives my users the ability to move the frame around and I was wondering how would I make it so when the users is clicking or the mouse is in the label, it shows a Cursor that I have made. I was just wondering what code would I use for this.


回答1:


In your MouseListener you can use:

event.getComponent().setCursor(...);

Read the Cursor API for more information. You can use the getPredefinedCursor() method.

The mousePressed() method would set the cursor. Then in the mouseReleased() method you would set the cursor to null to restore the default cursor.

Edit:

To use a custom cursor the basic code would be:

Cursor custom = Toolkit.getDefaultToolkit().createCustomCursor(...);

and you provide the image to use for the Cursor.



来源:https://stackoverflow.com/questions/19482427/custom-cursor-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!