Java 使用带有双精度值的 setText(..) 方法设置文本字段。图形用户界面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20596848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting the text field using setText(..) method with a double value. Java GUI
提问by user3102872
I'm trying to use setText(..)
and sending a double value to it but it says
我正在尝试使用setText(..)
并向其发送双倍值,但它说
setText(java.lang.String) in javax.swing.text.JTextComponent cannot be applied to (double)
回答by zbr
You need to convert your double
to a String
and then pass that String
as an argument to the setText(String)
method. This is how you convert a double
to a String
:
您需要将您的转换double
为 a String
,然后将其String
作为参数传递给该setText(String)
方法。这是将 a 转换double
为 a 的方式String
:
double d = 3.14;
String s = String.valueOf(d);
// s is now "3.14"