简体   繁体   English

如何设置 JFormattedTextField 的大小

[英]How to set size of JFormattedTextField

Hello I was just wondering is it possible to set the size of a JFormattedTextField like it is with a regular JTextField for example.您好,我只是想知道是否可以像使用常规 JTextField 一样设置 JFormattedTextField 的大小。

Below I have a normal JTextField and am just setting it to a decent size.下面我有一个普通的 JTextField,我只是将它设置为合适的大小。

 textField = new JTextField(20);//Setting the JTextFields size to 20

But say I was to have a JFormattedTextField as below how would I set the size of it I cant seem to find anything relating to it online any suggestions or help greatly appreciated.但是说我要有一个 JFormattedTextField,如下所示我将如何设置它的大小我似乎无法在网上找到任何与之相关的任何建议或帮助,非常感谢。

 textField =new JFormattedTextField(new DecimalFormat("###,###"));//This JFormattedTextField is being set so only decimals may be entered into it
    

Since JFormattedTextField extends from JTextField , you can use all of the methods available to the parent with the child, here the setColumns(...) method which will set the value for the displayed column width of the component.由于JFormattedTextFieldJTextField扩展而来,您可以将父级可用的所有方法与子级一起使用,这里是setColumns(...)方法,该方法将为组件的显示列宽设置值。 This is all as per the JFormattedTextField API .这一切都是按照JFormattedTextField API 进行的。

For example:例如:

// in the field declaration section
private JFormattedTextField textField = new JFormattedTextField(new DecimalFormat("###,###"));

// .....

// in the constructor
textField.setColumns(20);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM