[英]How to set format to a JFormattedTextField
I want to use a JFormattedTextField
that can input fraction numbers. 我想使用可以输入分数的JFormattedTextField
。 As Java doc specifies its format should set within the constructor. 正如Java doc指定的那样,其格式应在构造函数中设置。 But I'm using NetBeans IDE, the constructor of the JFormattedTextField
is a generated code , so I don't know how to specify a format. 但是我使用的是NetBeans IDE, JFormattedTextField
的构造函数是生成的代码,所以我不知道如何指定格式。
And if you can please direct me to a helpful tutorial. 如果可以的话,请引导我到有用的教程中。
To customize the creation code of a Swing element in NetBeans, right-click the element and select Customize code... . 要在NetBeans中自定义Swing元素的创建代码,请右键单击该元素,然后选择“ 自定义代码...” 。 In the following pop-up, click the drop-down menu next to the code snippet and select Custom creation . 在以下弹出窗口中,点击代码段旁边的下拉菜单,然后选择自定义创建 。 Then you can specify the code yourself as such: 然后,您可以自己指定代码,如下所示:
DecimalFormat df = DecimalFormat.getInstance();
// do some manipulation to the DecimalFormat object if desired
jFormattedTextField = new javax.swing.JFormattedTextField(df);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.