4 Replies Latest reply: Oct 17, 2012 7:08 PM by 968179 RSS

    Beep sound?

    968179
      How can I make a beep sound (for example as a cue to the operator when an invalid key is pressed)?

      AWT has Toolkit.getDefaultToolkit().beep().
      SWT has ... getDisplay().beep();
      How can accomplish the same in FX? (The AWT call fails in an FX environment.)
        • 1. Re: Beep sound?
          abg
          Toolkit.getDefaultToolkit().beep();

          works for me.

          alex
          • 2. Re: Beep sound?
            gimbal2
            abg wrote:
            Toolkit.getDefaultToolkit().beep();

            works for me.

            alex
            The fact if it works was not the question. But you're still right in a way - using the old AWT beep() functionality is still the way to go it seems. Or play your own sound through an AudioClip for example.

            Apparently there is a feature request for a beep through the JavaFX API:

            http://stackoverflow.com/questions/10636194/java-fx-2-alert-sound
            http://javafx-jira.kenai.com/browse/RT-21634

            (which has been rejected it seems).
            • 3. Re: Beep sound?
              shakir.gusaroff
                  Button button = new Button("Button");
                  button.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent actionEvent) {
                     
                      AudioClip plonkSound = new AudioClip("http://www.soundjay.com/mechanical/sounds/clong-1.mp3");
                      plonkSound.play();
                    }
                  });
              • 4. Re: Beep sound?
                968179
                Doesn't work for me on Mac OS X Java7u7.