问题描述
看起来类没有空白光标开始,所以可以使用方法。
以下是我尝试过的一种似乎工作的方式:
//透明的16 x 16像素光标图像。
BufferedImage cursorImg = new BufferedImage(16,16,BufferedImage.TYPE_INT_ARGB);
//创建一个新的空白游标。
Cursor blankCursor = Toolkit.getDefaultToolkit()。createCustomCursor(
cursorImg,new Point(0,0),blank cursor);
//将空白光标设置为JFrame。
mainJFrame.getContentPane()。setCursor(blankCursor);
编辑 p>
关于 JFrame
中没有游标的所有内容的评论,似乎包含在
将最终继承容器的游标( JFrame
中的组件 JFrame
),因此如果需要有一个组件
出现光标,则必须手动设置所需的光标。
例如,如果 JFrame
中包含 JPanel
可以使用方法:
JPanel p = ...
//将JPanel的光标设置为系统默认值。
p.setCursor(Cursor.getDefaultCursor());
Is there anyway to hide cursor other than using transparent gif image?
It appears that the Cursor
class does not have a "blank" cursor to begin with, so one could define a new "blank" cursor using the Toolkit.createCustomCursor
method.
Here's one way I've tried which seems to work:
// Transparent 16 x 16 pixel cursor image.
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
// Create a new blank cursor.
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
cursorImg, new Point(0, 0), "blank cursor");
// Set the blank cursor to the JFrame.
mainJFrame.getContentPane().setCursor(blankCursor);
Edit
Regarding the comment about everything inside the JFrame
ending up without a cursor, it seems that the Component
s which are contained in the JFrame
will end up inheriting the cursor of the container (the JFrame
), so if it is a requirement to have a certain Component
have the cursor appear, one would have to manually set the desired cursor.
For example, if there is a JPanel
contained in the JFrame
, then one could set the cursor of that JPanel
to the system's default using the Cursor.getDefaultCursor
method:
JPanel p = ...
// Sets the JPanel's cursor to the system default.
p.setCursor(Cursor.getDefaultCursor());
这篇关于如何在Swing应用程序中隐藏光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!