如何在Java中更改光标图标? [英] How to change cursor icon in Java?

查看:419
本文介绍了如何在Java中更改光标图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行Java应用程式时,我想将光标图示变更为自订的32x32图片。我查找和搜索,我发现只是设置光标在JComponent。但是我想让游标改变到我指定的图标,无论它移动,浏览和点击,只要Java应用程序仍在运行,或者你可以说程序运行时。


解决方案

标准光标图片:

  setCursor(Cursor.getDefaultCursor()); 

用户定义的图像:

  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);

您可以下载包含示例源的zip文件:这里


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.

解决方案

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

这篇关于如何在Java中更改光标图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆