Why does Toolkit.getDefaultToolkit().beep() not work in Windows?

15,668

Solution 1

This code works for me on Windows 7, make sure you don't have your sound muted.

import java.awt.*;

public class Beep {
    public static void main(String... args) {
        Toolkit.getDefaultToolkit().beep();     
    }
}

You could also just print the ASCII representation for the bell, also works on Windows 7

public class Beep {
    public static main(String... args) {
       System.out.print("\007"); // \007 is the ASCII bell
       System.out.flush();
    }
}

Solution 2

For me, the problem was that I had "No Sounds" configured (Win7 Pro). After changing this back to "Windows Default", I was able to hear the beep (actually a 'ding') - also when started from within eclipse.

Share:
15,668
Daniel Causebrook
Author by

Daniel Causebrook

Updated on July 04, 2022

Comments

  • Daniel Causebrook
    Daniel Causebrook almost 2 years

    When I try to get a beep by using Toolkit.getDefaultToolkit().beep(), it does not seem to work on any of my Windows computers. I also know someone who has the same problem, but they say it works on other OS's. Does anyone know why?