Java-自定义光标在不同操作系统中是不同的
我使用底部代码创建自定义光标:
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.getImage("C:/Users/Administrator/Desktop/gaea/core/ui/gaeawindow/src/si/xlab/gaea/core/ui/gaeawindow/HandCursor.gif");
// Somewhere in mouse pressed action
public void mousePressed(MouseEvent e)
{
Cursor cursor = toolkit.createCustomCursor(imageClose, new Point(12,12), "Hand");
e.getComponent().setCursor(cursor);
}
光标在 Mac 上显示应有的样子,但在模拟的 Windows 7 中却不然。它显示增加并且很难看。
我应该对我的代码应用什么修复/技巧来解决这个问题?这是常见问题吗?
I create custom cursor with bottom code:
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.getImage("C:/Users/Administrator/Desktop/gaea/core/ui/gaeawindow/src/si/xlab/gaea/core/ui/gaeawindow/HandCursor.gif");
// Somewhere in mouse pressed action
public void mousePressed(MouseEvent e)
{
Cursor cursor = toolkit.createCustomCursor(imageClose, new Point(12,12), "Hand");
e.getComponent().setCursor(cursor);
}
Cursor is shown on Mac like it should be, but in emulated Windows 7 it isn't. It's shown increased and it's ugly.
What fix/trick should i apply to my code to fix this? Is this common problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 Windows 需要 32x32 光标,如果不是,则会缩放图像。
Mac 更加灵活。
最简单的解决方案是使用透明像素将现有的 16x16 光标填充到 32x32;这将在两个平台上运行。
您可以使用它
来查看是否支持给定的大小。
有关更多信息,请参阅:
http://forums.sun.com/thread.jspa?threadID=5424409
其中还有 MS 网站的链接。
The problem is that Windows wants 32x32 cursors and will scale your image if it isn't.
The Mac is more flexible.
The easiest solution is to pad your existing 16x16 cursors out to 32x32 with transparent pixels; this will then work on both platforms.
You can use
to see if a given size is supported.
For more info, see:
http://forums.sun.com/thread.jspa?threadID=5424409
which also has a link to the MS site.
可能是模拟Windows 7找不到图像文件。
您应该将图像文件移动到 java 文件旁边的类路径中,以便可以使用 getClass().getResource() 加载该文件。
它应该可以在模拟的 Windows 7 和 Mac 上运行。
Probably emulated Windows 7 cant find the image file.
You should move image file into classpath, next to your java files, so that you can load this file with getClass().getResource().
It should work on both emulated Windows 7 and Mac.