JSpinnerのフォント指定
JSpinner#setFont()を実行しても、指定したフォントはエディタに反映されない。
ならばgetEditor()を呼んで
spinner.getEditor().setFont(font);
と書けば良いかというと、それも駄目。getEditor()の戻り値の実体はテキストフィールドを持ったパネルなので、
spinner.getEditor().getComponent(0).setFont(font);
とする。
実は、これでもまだ駄目。JSpinnerは値が変更されるたびにエディタコンポーネントを作り直すので、そのタイミングでフォントがリセットされてしまう。
最終的な対応策は以下。
public class MySpinner extends JSpinner { private static final long serialVersionUID = 1L; public void setFont(Font font) { super.setFont(font); updateEditorFont(); } public void setEditor(JComponent editor) { super.setEditor(editor); updateEditorFont(); } public void updateEditorFont() { getEditor().getComponent(0).setFont(getFont()); } }