JOptionPaneのタイトルバー背景色をMessageTypeに応じて変更する
Total: 1414, Today: 2, Yesterday: 2
Posted by aterai at
Last-modified:
Summary
JOptionPaneのタイトルバー背景色や縁色などをMessageTypeに対応した色に変更します。
Screenshot

Advertisement
Source Code Examples
JDialog.setDefaultLookAndFeelDecorated(true);
JOptionPane.showMessageDialog(parent, msg, title, JOptionPane.ERROR_MESSAGE);
View in GitHub: Java, KotlinDescription
JDialog.setDefaultLookAndFeelDecorated(true)を実行してMetalLookAndFeelがウィンドウ装飾をサポートするよう設定JFrame.setDefaultLookAndFeelDecorated(true)はJDialogを使用するJOptionPaneのウィンドウ装飾には影響しない- JFrameがデフォルトのウィンドウ装飾を使用する場合のタイトルバー背景色を変更
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)で変更可能
Reference
- JFrameがデフォルトのウィンドウ装飾を使用する場合のタイトルバー背景色を変更
- JDialog#setDefaultLookAndFeelDecorated(boolean) (Java Platform SE 8)