Java:完全禁用任何 Swing 不需要的蜂鸣声的方法?
我正在使用 Swing 开发一个相当复杂的 Java 应用程序。
在某些情况下,无需任何用户干预就会发出不需要的蜂鸣声。没有崩溃,应用程序保持正常工作,我尊重 EDT 规则等。
但在某些情况下,可以听到蜂鸣声:我可能做了一些愚蠢的事情,触发了蜂鸣声,但无论如何,这不是用户操作,因为它可能发生当用户离开时导入数据。
对于一个永远不应该发出任何声音的 Java 应用程序,是否有可能通过为整个应用程序设置一个属性来配置它:“永远不要发出蜂鸣声”?
我一直在谷歌上搜索这个问题,我发现了有同样问题但没有答案的人的消息:我发现的只是一些黑客说 JEditorPane 存在一个已知问题并且使用 putProperty("IgnoreCharsetDirective", Boolean.TRUE)
有助于减少不必要的蜂鸣声发生。然而,关于这个主题的信息非常匮乏。
这是一个真正的问题,因为该应用程序是在计算机上需要声音的环境中使用的,但这个 Java 应用程序发出的噪音是不可接受的。
I am working on a fairly complex Java application using Swing.
On some occasions there are unwanted beeps without any user intervention. No crash, application keeps working fine, I'm respecting the EDT rules etc.
Yet in some cases a beep can be heard: I may be doing something silly triggering that beep but in any case it s not a user action for it can happen upon importing data, when the user is away.
Is it possible, for a Java application that should never ever emit any sound to configure it, say by setting a property for the whole application that says: "dont' ever emit a beep"?
I ve been Googling for that issue and I ve found message by people having the same issue but no answer: all I found was some hack saying that there was a known issue with JEditorPane and that using a putProperty("IgnoreCharsetDirective", Boolean.TRUE)
was helpful to make unwanted beeps happen less often. Yet information is very scarce on the subject.
It s a real issue because the application is used in an environment where the sound is needed on the computer, but this Java application emitting noise is unacceptable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题已在 Java 论坛上讨论:
注意:
不鼓励使用此解决方法。您仍然应该尝试找到问题的根源。编辑:删除了一个链接,因为 Java 论坛上的线程现已离线。
Your problem is discussed on the Java Forum:
NOTE:
The use of this workaround is discouraged. You should still try to find the root of the problem.Edit: Removed a link, since the thread on Java Forum is now offline.
在 Swing 中,您需要按如下方式重写
LookAndFeel
:通常,您的蜂鸣决定将引用应用程序的某种外部配置/首选项标志。
In Swing you need to override the
LookAndFeel
as follows:Typically your beep decision would reference some kind of external configuration/preferences flag for your application.