Posted by mkarg
on January 3, 2010 at 7:32 AM PST
It took me several sleepless nights to find out, but finally I got it - and was astonished how easy it is. Ever wanted to play the default system sound for a specific operation? Well, in fact there is no platform independent solution for that (can't believe it, I know, but it is true). But at least Swing internally does it that way on the Windows platform (and on other platforms it will just do nothing, so it is at least safe not to crash on other platforms):
final Runnable runnable = Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
if (runnable != null)
Yes, folk's, it's really such easy!
But what to do on other platforms? I don't know, actually. Maybe someone else ever might find out. Or Sun creates an API for that. :-)
So you like playing more sounds? Just change the name of the String property. A list of all possible values can be found here: java.sun.com/j2se/1.4.2/docs/guide/swing/1.4/w2k_props.html