简体   繁体   English

有没有办法为Java Swing应用程序设置默认的鼠标光标图像?

[英]Is there a way to set the default mouse cursor image for a java Swing application?

I'm working with a large java swing application. 我正在使用大型Java swing应用程序。 The customer wants to have a larger cursor image for the mouse because of the limitations (space) of the monitors that can be used for the application. 由于可用于该应用程序的监视器的局限性(空间),客户希望为鼠标提供更大的光标图像。

The way to do this for a single Swing JFrame instance is something like: 对单个Swing JFrame实例执行此操作的方法类似于:

Image image = toolkit.getImage("resources/NetworkGreen48.gif"); Cursor customCursor = toolkit.createCustomCursor(image , new Point(0, 8), "img"); mainJFrame.setCursor (customCursor);

this works fine for the mainJFrame JFrame and any components embedded on the mainJFrame JFrame. 这对于mainJFrame JFrame以及mainJFrame JFrame上嵌入的任何组件都适用。

However, this application has literally hundreds of independent JFrames, JDialogs, etc. For these, running in the same JVM, but not actively added to the mainJFrame JFrame, the cursor reverts to the operating system default. 但是,此应用程序实际上具有数百个独立的JFrame,JDialogs等。对于这些运行在同一JVM中但未主动添加到mainJFrame JFrame中的JFrame,光标将恢复为操作系统默认值。

Is there a good way to set the mouse cursor for ALL the places the mouse will be used in the Swing application? 是否有一种很好的方法来为Swing应用程序中将使用鼠标的所有位置设置鼠标光标?

Considered doing it by talking to the OS, but, this application is running on Windows currently and will run on some version of linux in the future so I'd better not depend on the OS. 考虑通过与OS进行通信来实现此目的,但是,此应用程序当前正在Windows上运行,并且将来会在某些版本的Linux上运行,因此我最好不要依赖OS。

I can do this on a Frame by Frame basis. 我可以逐帧执行此操作。 Would just like to know if there is a better way. 只是想知道是否有更好的方法。

first part : custom cursor I was searching to define this using look and feel but i didn't find anything about loding custom cursor inside, so there is 2 solution always use a custom sub class of JFrame where the method frameInit is override to use your cursor. 第一部分:自定义游标我正在使用外观来定义此游标,但是我没有找到关于在其中放置自定义游标的任何内容,因此有2种解决方案始终使用JFrame的自定义子类,其中方法frameInit被覆盖以使用您的光标。 Or use a factory to create all the frame you need to set the property as you do before. 或使用工厂来创建所有需要设置属性的框架,就像之前一样。

Swing is not completely os independant i think that you see few rendering difference between the os you use. 摆动并不是完全独立于操作系统,我认为您所使用的操作系统之间几乎没有渲染差异。 The only think that change is the look and feel(laf or plaf), each OS use its own plaf. 唯一认为更改是外观(laf或plaf),每个OS都使用自己的plaf。 but there is a cross OS Laf call Metal. 但是有一个跨OS Laf的电话,称为Metal。 Here is the documentation related to how change laf : 以下是有关如何更改laf的文档:

https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

to be sure to be cross OS its recommanded to work using Metal but it's not required. 为了确保可以跨操作系统使用,建议使用Metal来工作,但这不是必需的。

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

相关问题 在Swing中,是否可以从工具箱中提取预定义的鼠标光标图像? - In Swing, is there a way to extract a predefined mouse cursor Image from the toolkit? 如何让Java Swing应用程序显示Compiz Mouse Plugin(Ubuntu)的鼠标光标效果 - How to make Java Swing application show mouse cursor effects of Compiz Mouse Plugin (Ubuntu) Java中的自定义鼠标光标绘图(摆动) - Custom mouse cursor drawing in Java (swing) Java摆动“在后台工作”鼠标光标 - Java swing “working in background” mouse cursor 当鼠标在应用程序窗口之外时,是否可以在从摇摆中拖动(我的意思是图像,而不是位置)时更改鼠标光标? - Is it possible to change mouse cursor when dragging (I mean image, not position) from swing when mouse is outside application window? 在 OS X 上的 Java swing 中设置默认应用程序图标图像 - Setting the default application icon image in Java swing on OS X 在应用程序开始Java swing前等待光标 - Wait cursor before the Application starts Java swing 如何在Java AWT和/或Swing中更改光标图像? - How to change the cursor image in Java AWT and/or Swing? Java Swing:设置可点击背景图像的最佳方法 - Java Swing : best way to set background image clickable 用于在Java Swing中设置光标的图像参数 - Image parameters for setting cursor in Java Swing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM