Java: way to completely disable any unwanted Swing beeps?

I am working on a rather complicated Java application using Swing.

In some cases, unwanted sound signals appear without user intervention. No crashes, the application does not work fine, I respect EDT rules, etc.

However, in some cases you can hear a beep: I can do something stupidly by causing this beep, but in any case this is not a user action that can happen when importing data when the user leaves.

Is it possible that a Java application that should never emit any sound to configure it, say by setting a property for the entire application that says: โ€œdont" never emit a sound "?

I was Google for this problem, and I found a message from people having the same problem, but did not answer: all I found was a hack saying that there was a known problem with JEditorPane, and that using putProperty("IgnoreCharsetDirective", Boolean.TRUE) was useful for making unwanted audio signals happen less frequently. However, there is very little information on this issue.

This is a real problem because the application is used in an environment where sound is needed on the computer, but this noise application of a Java application is unacceptable.

+4
source share
2 answers

Your issue is discussed in the Java forum:

 // Write a custom toolkit public class MyToolkit extends sun.awt.windows.WToolkit { public void beep() { } } // Set this property System.setProperty("awt.toolkit", "MyPackage.MyToolkit"); 

NOTE: Using this workaround is not recommended. You should still try to find the root of the problem.


Edit: Removed link since thread on Java Forum is now disabled.

+4
source

In Swing, you need to override LookAndFeel as follows:

 UIManager.setLookAndFeel(new NimbusLookAndFeel() { @Override public void provideErrorFeedback(Component component) { // Your beep decision goes here // You want error feedback super.provideErrorFeedback(component); } }); 

Typically, your decision about an audio signal will refer to some external configuration / preference flag for your application.

0
source

Source: https://habr.com/ru/post/1301341/


All Articles