• category: swing folder: YesLastOptionPane title: JOptionPaneのYesボタンがCancelボタンなどの中で末尾に配置されるよう設定する tags: [JOptionPane] author: aterai pubdate: 2018-01-15T14:42:52+09:00 description: JOptionPaneのYesボタンがCancelボタンなどの後に追加されて一番右に配置されるよう設定します。 image: https://drive.google.com/uc?id=12DSo9IIp_Ah9F2FlvkEjjREEwZXyNNLWhA

概要

JOptionPaneYesボタンがCancelボタンなどの後に追加されて一番右に配置されるよう設定します。

サンプルコード

private static final String KEY = "OptionPane.isYesLast";

JButton defaultButton = new JButton(KEY + ": false(default)");
defaultButton.addActionListener(e -> {
  UIManager.put("OptionPane.isYesLast", Boolean.FALSE);
  String str = JOptionPane.showInputDialog(getRootPane(), KEY + ": false");
  log.setText(str);
});

JButton yesLastButton = new JButton(KEY + ": true");
yesLastButton.addActionListener(e -> {
  UIManager.put("OptionPane.isYesLast", Boolean.TRUE);
  String str = JOptionPane.showInputDialog(getRootPane(), KEY + ": true");
  log.setText(str);
});
View in GitHub: Java, Kotlin

解説

  • OptionPane.isYesLast: false(default)
    • WindowsLookAndFeelでのデフォルトでYesボタン(YES_OPTION)やOKボタン(OK_OPTION)を各オプションボタンの中で先頭(左端)に配置する
    • JOptionPane#setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT)が設定されている場合、先頭は右端になる
  • OptionPane.isYesLast: true
    • Yesボタンを各オプションボタンの中で末尾(右端)に配置する
    • MotifLookAndFeelNimbusLookAndFeelでもこの設定は有効
    • JOptionPane#setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT)が設定されている場合、末尾は左端になる

参考リンク

コメント