java样式中cursor,自定义Cursor java

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.

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值