Java: way to completely disable any Swing unwanted beeps?

后端 未结 2 826
生来不讨喜
生来不讨喜 2020-12-21 02:09

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

相关标签:
2条回答
  • 2020-12-21 02:42

    Your problem is discussed on 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: 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.

    0 讨论(0)
  • 2020-12-21 02:45

    In Swing you need to override the 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 beep decision would reference some kind of external configuration/preferences flag for your application.

    0 讨论(0)
提交回复
热议问题