• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JSpinnerの値をパーセントで指定
#navi(../)
*JSpinnerの値をパーセントで指定 [#t29c7b07]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2005-10-31~
更新日:&lastmod;
---
category: swing
folder: NumberEditor
title: JSpinnerの値をパーセントで指定
tags: [JSpinner]
author: aterai
pubdate: 2005-10-31T11:17:46+09:00
description: JSpinnerの値をパーセントで指定するように設定します。
image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTQecBWSoI/AAAAAAAAAfo/IOSdDmzOIBs/s800/NumberEditor.png
---
* 概要 [#summary]
`JSpinner`の値をパーセントで指定するように設定します。

#contents
#download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTQecBWSoI/AAAAAAAAAfo/IOSdDmzOIBs/s800/NumberEditor.png)

**概要 [#v1407fe1]
JSpinnerの値をパーセントで指定するように設定します。

#screenshot

**サンプルコード [#k32fce56]
#code{{
 JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, 1, 0.01));
 JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner, "0%");
 editor.getTextField().setEditable(false);
 spinner.setEditor(editor);
* サンプルコード [#sourcecode]
#code(link){{
JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, 1, .01));
JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner, "0%");
editor.getTextField().setEditable(false);
spinner.setEditor(editor);
}}
-&jnlp;
-&jar;
-&zip;

**解説 [#af34e284]
JSpinner.NumberEditorのコンストラクタに、DecimalFormatオブジェクトのパターンを入力すると数値の解析とフォーマットを行ってくれます。
* 解説 [#explanation]
- `JSpinner.NumberEditor`のコンストラクタに`DecimalFormat`オブジェクトのパターンを設定して数値の表示フォーマットを変更
- 数字を表す`0`と`100`倍してパーセントを表す`%`を組み合わせたフォーマットパターンを使用

上記のサンプルでは、数字を表す"0"と、100倍してパーセントを表す"%"を組み合わせたフォーマットパターンを使用しています。
* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JSpinner.NumberEditor.html JSpinner.NumberEditor (Java Platform SE 8)]

//**参考リンク
**コメント [#f777681c]
* コメント [#comment]
#comment
#comment