简体   繁体   English

在 Java 中设置游标

[英]Setting Cursor In Java

I've been trying to work out the Windows Cursors.我一直在尝试解决 Windows 光标。 I've successfully matched the Registry values to the names given to the various cursor types in the Mouse Properties dialog (the one accessed via the Control Panel).我已经成功地将注册表值与“鼠标属性”对话框(通过控制面板访问的那个)中各种光标类型的名称相匹配。

For example, what the Registry calls the 'AppStarting' cursor, the Mouse Properties dialog calls the 'Working In Background' cursor, and so on.例如,注册表称为“AppStarting”光标,鼠标属性对话框称为“后台工作”光标,等等。

Where I'm having trouble is using Java to set those cursors, because for many of them there doesn't appear to be a constant.我遇到麻烦的地方是使用 Java 来设置这些游标,因为对于其中的许多游标来说,似乎没有一个常量。 In Cursor.java the various cursors are defined:在 Cursor.java 中定义了各种游标:

public static final int DEFAULT_CURSOR = 0;
public static final int CROSSHAIR_CURSOR = 1;
public static final int TEXT_CURSOR = 2;
public static final int WAIT_CURSOR = 3;
public static final int SW_RESIZE_CURSOR = 4;
public static final int SE_RESIZE_CURSOR = 5;
public static final int NW_RESIZE_CURSOR = 6;
public static final int NE_RESIZE_CURSOR = 7;
public static final int N_RESIZE_CURSOR = 8;
public static final int S_RESIZE_CURSOR = 9;
public static final int W_RESIZE_CURSOR = 10;
public static final int E_RESIZE_CURSOR = 11;
public static final int HAND_CURSOR = 12;
public static final int MOVE_CURSOR = 13;

But, after some testing, there are several registry values to which none of them correspond.但是,经过一些测试,有几个注册表值与它们都不对应。 For example, the registry 'App Starting', 'Help', 'No', 'NWPen', 'Person', 'Pin' and 'UpArrow' entries have no corresponding definition (and they're not just the ints after 13; I got a violation when I used 14 as the value).例如,注册表中的“App Starting”、“Help”、“No”、“NWPen”、“Person”、“Pin”和“UpArrow”条目没有相应的定义(它们不仅仅是 13 之后的整数;当我使用 14 作为值时,我遇到了违规)。

More surprisingly, the registry 'Hand' value doesn't actually correspond to the HAND_CURSOR value.更令人惊讶的是,注册表“Hand”值实际上并不对应于 HAND_CURSOR 值。 Setting a new cursor for the HAND_CURSOR definition doesn't change the value stored in the registry for the 'Hand' key.为 HAND_CURSOR 定义设置新游标不会更改注册表中存储的“Hand”键值。

So how do I set, say, the AppStarting cursor value using Java?那么如何使用 Java 设置 AppStarting 游标值呢?

Info: Windows 10 64-bit jdk1.8.0_151信息:Windows 10 64 位 jdk1.8.0_151

I found an answer here that says:我在这里找到了一个答案,上面写着:

The Java Runtime Environment requires that custom cursors are in PNG or GIF format. Java 运行时环境要求自定义光标为 PNG 或 GIF 格式。 Just because you are using Java on a Windows system does not mean that you can use that format for a GUI in Swing/AWT.仅仅因为您在 Windows 系统上使用 Java 并不意味着您可以在 Swing/AWT 中为 GUI 使用该格式。

However, I was able to find this in the documentation, so maybe you'll be able to pull the specific cursor you'll looking for by it's name.但是,我能够在文档中找到,所以也许您可以通过它的名称来拉出您要查找的特定光标。 From that documentation:从该文档:

Returns a system-specific custom cursor object matching the specified name.返回与指定名称匹配的特定于系统的自定义游标对象。 Cursor names are, for example: "Invalid.16x16"光标名称是,例如:“Invalid.16x16”

Edit: The second part is not for pulling from the system, rather, the cursors included with the JRE.编辑:第二部分不是用于从系统中提取,而是用于 JRE 中包含的游标。 See this question .看到这个问题

Edit 2: I found this package that has an AppStarting cursor that may fit your needs... If you include the package.编辑 2:我发现这个包一个AppStarting 光标,可能适合你的需要......如果你包含这个包。 Since it's a Cursor object it should serve your purpose.由于它是一个 Cursor 对象,因此它应该可以满足您的目的。

Edit 3: Information about draw2d on eclipse.org can be found here .编辑 3:可以在此处找到 eclipse.org 上有关 draw2d 的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM