• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JSpinnerの文字列を非表示にする
#navi(../)
#tags()
RIGHT:Posted by &author(aterai); at 2009-08-03
*JSpinnerの文字列を非表示にする [#yf2c696d]
SpinnerNumberModelを使用するJSpinnerを無効にしたとき、数値を非表示にします。
---
category: swing
folder: DecimalFormatSymbols
title: JSpinnerの文字列を非表示にする
tags: [JSpinner, SpinnerNumberModel, JFormattedTextField, DecimalFormatSymbols]
author: aterai
pubdate: 2009-08-03T20:40:16+09:00
description: SpinnerNumberModelを使用するJSpinnerを無効にしたとき、数値を非表示にします。
image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTKfhstbcI/AAAAAAAAAWE/MMaDVyQ9jNY/s800/DecimalFormatSymbols.png
---
* 概要 [#summary]
`SpinnerNumberModel`を使用する`JSpinner`を無効にしたとき、数値を非表示にします。

-&jnlp;
-&jar;
-&zip;
#download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTKfhstbcI/AAAAAAAAAWE/MMaDVyQ9jNY/s800/DecimalFormatSymbols.png)

//#screenshot
#ref(http://lh4.ggpht.com/_9Z4BYR88imo/TQTKfhstbcI/AAAAAAAAAWE/MMaDVyQ9jNY/s800/DecimalFormatSymbols.png)

**サンプルコード [#a40d872c]
* サンプルコード [#sourcecode]
#code(link){{
private static JSpinner makeSpinner1(SpinnerNumberModel m) {
  JSpinner s = new JSpinner(m);
  JFormattedTextField ftf = getJFormattedTextField(s);
  DecimalFormatSymbols dfs = new DecimalFormatSymbols();
  ftf.setFormatterFactory(makeFFactory(dfs));
  ftf.setDisabledTextColor(UIManager.getColor("TextField.disabledColor"));
  return s;
}
}}
#code{{

private static JSpinner makeSpinner2(SpinnerNumberModel m) {
  JSpinner s = new JSpinner(m);
  JFormattedTextField ftf = getJFormattedTextField(s);
  DecimalFormatSymbols dfs = new DecimalFormatSymbols();
  dfs.setNaN(" ");
  ftf.setFormatterFactory(makeFFactory(dfs));
  return s;
}
}}

**解説 [#e7cbe202]
+デフォルト
+JSpinnerからJFormattedTextFieldを取得し、この無効の場合の文字色を無効場合の背景色と同じにして、非表示になるようにしています。
+JSpinnerからJFormattedTextFieldを取得し、DecimalFormatSymbols#setNaNメソッドを使用して、値がNaNの場合、表示する文字列をスペースに変更しています。
+JSpinnerからJFormattedTextFieldを取得し、DecimalFormatSymbols#setNaNメソッドを使用して、値がNaNの場合、表示する文字列を"----"に変更しています。
* 解説 [#explanation]
- デフォルト
- 非表示
-- `JSpinner`から`JFormattedTextField`を取得し、無効の場合の文字色を無効場合の背景色と同じにして非表示化
- 半角スペース
-- `JSpinner`から`JFormattedTextField`を取得し、`DecimalFormatSymbols#setNaN(...)`メソッドを使用して値が`NaN`の場合は表示する文字列を半角スペース(`U+0020`)に変更
- `----`
-- `JSpinner`から`JFormattedTextField`を取得し、`DecimalFormatSymbols#setNaN(...)`メソッドを使用して値が`NaN`の場合は表示する文字列を`----`に変更

//**参考リンク
**コメント [#v85ff054]
* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/java/text/DecimalFormatSymbols.html DecimalFormatSymbols (Java Platform SE 8)]

* コメント [#comment]
#comment
#comment