AuditoryCuesでイベント音を設定する
Total: 9277, Today: 1, Yesterday: 0
Posted by aterai at
Last-modified:
Summary
UIManagerにAuditoryCues.playListを設定して、ダイアログが開いた時の警告音などを鳴らします。
Screenshot

Advertisement
Source Code Examples
Object[] optionPaneAuditoryCues = {
"OptionPane.errorSound",
"OptionPane.informationSound",
"OptionPane.questionSound",
"OptionPane.warningSound"
};
// UIManager.put(
// "AuditoryCues.playList",
// UIManager.get("AuditoryCues.allAuditoryCues"));
// UIManager.put(
// "AuditoryCues.playList",
// UIManager.get("AuditoryCues.defaultCueList"));
// UIManager.put(
// "AuditoryCues.playList",
// UIManager.get("AuditoryCues.noAuditoryCues"));
UIManager.put("AuditoryCues.playList", optionPaneAuditoryCues);
View in GitHub: Java, KotlinDescription
上記のサンプルでは、デフォルトではすべて再生しないように設定されている聴覚フィードバックを、JOptionPaneでダイアログを開いた場合のみ有効になるように変更しています。
showMessageDialog1LookAndFeelデフォルトの音が鳴る(LookAndFeelにデフォルトの音が無い場合は鳴らない)WindowsLookAndFeelでは、「コントロールパネル」「サウンドとオーディオデバイスのプロパティ」で、プログラムイベントが設定されている場合は音が鳴る
showMessageDialog2- 別途用意した
wavファイルを再生する UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.noAuditoryCues"))として、二重に鳴らないように制限
- 別途用意した
MetalLookAndFeelやMotifLookAndFeelでは以下のようにMessageDialogのイベント音の変更が可能UIManager.put("OptionPane.informationSound", "/example/notice2.wav");
Reference
- Swingコンポーネントの音声フィードバック - Java™ SE 1.4でのSwingの変更点および新機能
- Merlinの魔術: Swingのオーディオ
- "taitai studio" フリーWav素材集
- Beep音を鳴らす
- MIDIファイルの演奏
- Wavファイルの演奏