TITLE:MetalLookAndFeelで太字フォントを使用しない

Posted by at 2013-01-21

MetalLookAndFeelで太字フォントを使用しない

`MetalLookAndFeel`で太字フォントを使用しないように設定します。

  • &jnlp;
  • &jar;
  • &zip;
BoldMetal.png

サンプルコード

UIManager.put("swing.boldMetal", Boolean.FALSE);
View in GitHub: Java, Kotlin

解説

上記のサンプルでは、`UIManager.put("swing.boldMetal", Boolean.FALSE);として、JLabelJButtonTitleBorder`などのデフォルトとしてボールド(太字)フォントを使用しないように設定しています。

システムプロパティー`swing.boldMetalfalse`に設定する方法でもボールド(太字)フォントを使用しないように設定することができます。

> java -Dswing.boldMetal=false example.MainPanel
  • デフォルトプロパティー`swing.boldMetalが、システムプロパティーswing.boldMetal`より優先される
  • `Html<html><b>...</b></html>のように装飾した場合は、デフォルトプロパティーswing.boldMetalより優先される(このサンプルでは、JTabbedPaneの選択タブタイトルを<html><b>...</b></html>`で装飾)
  • 以下のようにデフォルトプロパティー`swing.boldMetal`を更新することで切り替え可能
JCheckBox check = new JCheckBox("swing.boldMetal");
check.addActionListener(new ActionListener() {
  @Override public void actionPerformed(ActionEvent e) {
    JCheckBox c = (JCheckBox)e.getSource();
    UIManager.put("swing.boldMetal", c.isSelected());
    // re-install the Metal Look and Feel
    try{
      UIManager.setLookAndFeel(new MetalLookAndFeel());
    }catch(Exception ex) {
      ex.printStackTrace();
    }
    // Update the ComponentUIs for all Components. This
    // needs to be invoked for all windows.
    SwingUtilities.updateComponentTreeUI(SwingUtilities.getWindowAncestor(c));
  }
});

参考リンク

コメント