---
category: swing
folder: BoldMetal
title: MetalLookAndFeelで太字フォントを使用しない
tags: [MetalLookAndFeel, LookAndFeel, Font, UIManager, Html]
author: aterai
pubdate: 2013-01-21T00:02:35+09:00
description: MetalLookAndFeelで太字フォントを使用しないように設定します。
image: https://lh4.googleusercontent.com/-7wQtHGyNRDQ/UPv6YyOBReI/AAAAAAAABbk/_vXFoJwk-ug/s800/BoldMetal.png
---
* Summary [#summary]
`MetalLookAndFeel`で太字フォントを使用しないように設定します。
#download(https://lh4.googleusercontent.com/-7wQtHGyNRDQ/UPv6YyOBReI/AAAAAAAABbk/_vXFoJwk-ug/s800/BoldMetal.png)
* Source Code Examples [#sourcecode]
#code(link){{
UIManager.put("swing.boldMetal", Boolean.FALSE);
}}
* Description [#explanation]
* Description [#description]
上記のサンプルでは、`UIManager.put("swing.boldMetal", Boolean.FALSE);`として`JLabel`、`JButton`、`TitledBorder`などのデフォルトとしてボールド(太字)フォントを使用しないように設定しています。
- システムプロパティー`swing.boldMetal`を`false`にしてボールド(太字)フォントを使用しないように設定する方法もある
> java -Dswing.boldMetal=false example.MainPanel
- デフォルトプロパティーの`swing.boldMetal`がシステムプロパティーの`swing.boldMetal`より優先される
- `Html`で`<html><b>...</b></html>`のように装飾した場合は、デフォルトプロパティー`swing.boldMetal`より優先される
-- このサンプルでは`JTabbedPane`の選択タブタイトルを`<html><b>...</b></html>`で装飾
- 以下のようにデフォルトプロパティー`swing.boldMetal`を更新することで切り替え可能
-- [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/plaf/metal/DefaultMetalTheme.html DefaultMetalTheme (Java Platform SE 8)]
#code{{
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));
}
});
}}
* Reference [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/plaf/metal/DefaultMetalTheme.html DefaultMetalTheme (Java Platform SE 8)]
* Comment [#comment]
#comment
#comment