次のように、Jtextfield の型を double 値に変更しようとしています。
rangespaceField3.setText(bmi.getBMI());
getBMI メソッドは double 値を返しますが、次のエラーが発生します。
JTextComponent は引数に適用されません (double)
次のように、Jtextfield の型を double 値に変更しようとしています。
rangespaceField3.setText(bmi.getBMI());
getBMI メソッドは double 値を返しますが、次のエラーが発生します。
JTextComponent は引数に適用されません (double)
これを試して:
rangespaceField3.setText(String.valueOf(bmi.getBMI()));
String.valueOf
プリミティブ データ型の文字列表現を返します。
JFormattedTextField に基づいて数値フィールドを実装しました。
JRealNumberField と JLocalizedRealNumberField は、BigDecimal のテキスト フィールドです。
また、最小値と最大値もサポートしています。
便利だと思うかもしれません (ライブラリはオープンソースです):
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JRealNumberField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JDoubleField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JFloatField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLocalizedDoubleField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLocalizedFloatField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JWholeNumberField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JByteField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JIntegerField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLongField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JShortField.html
チュートリアル:
http://softsmithy.sourceforge.net/lib/docs/tutorial/swing/number/index.html
ホームページ:
ダウンロード:
http://sourceforge.net/projects/softsmithy/files/softsmithy/
メイヴン:
<dependency>
<groupid>org.softsmithy.lib</groupid>
<artifactid>lib-core</artifactid>
<version>0.1</version>
</dependency>
試すrangespaceField3.setText(Double.toString(bmi.getBMI()));
double の文字列表現をテキスト フィールドに入力することだけが必要な場合は、String クラスの valueOf() メソッドを使用します。
rangespaceField3.setText(String.valueOf(bmi.getBMI()));
これを試してみてください....
// double 値を空の文字列と連結し、double を文字列に変換します
rangespaceField3.setText(bmi.getBMI()+"");
OR
// メソッドから返された double 値に対して toString() を呼び出します。これも String に変換されます
rangespaceField3.setText(bmi.getBMI().toString());