• category: swing folder: OptionPaneMessageTypeColor title: JOptionPaneのタイトルバー背景色をMessageTypeに応じて変更する tags: [JOptionPane, MetalLookAndFeel] author: aterai pubdate: 2022-12-05T08:32:32+09:00 description: JOptionPaneのタイトルバー背景色や縁色などをMessageTypeに対応した色に変更します。 image: https://drive.google.com/uc?id=1AVd6cPRb_L98qWsiVXcNaQ8LYNvJB9T_

概要

JOptionPaneのタイトルバー背景色や縁色などをMessageTypeに対応した色に変更します。

サンプルコード

JDialog.setDefaultLookAndFeelDecorated(true);
JOptionPane.showMessageDialog(parent, msg, title, JOptionPane.ERROR_MESSAGE);
View in GitHub: Java, Kotlin

解説

  • JDialog.setDefaultLookAndFeelDecorated(true)を実行してMetalLookAndFeelがウィンドウ装飾をサポートするよう設定
  • JOptionPane.PLAIN_MESSAGE
    • デフォルトのウィンドウ装飾を適用
  • JOptionPane.ERROR_MESSAGE
    • エラーダイアログのウィンドウ装飾を適用
    • エラーダイアログのタイトルバー背景色はUIManager.put("OptionPane.errorDialog.titlePane.background", color)で変更可能
  • JOptionPane.INFORMATION_MESSAGE
    • 情報ダイアログのウィンドウ装飾はデフォルトと同一
  • JOptionPane.WARNING_MESSAGE
    • 警告ダイアログのウィンドウ装飾を適用
    • 警告ダイアログのタイトルバー背景色はUIManager.put("OptionPane.warningDialog.titlePane.background", color)で変更可能
  • JOptionPane.QUESTION_MESSAGE
    • 質問ダイアログのウィンドウ装飾を適用
    • 質問ダイアログのタイトルバー背景色はUIManager.put("OptionPane.questionDialog.titlePane.background", color)で変更可能

参考リンク

コメント