我有几个具有某些格式的文本字段:百分比格式、日期格式等:
DateFormat dfm= new SimpleDateFormat("yyyy-MM-dd");
textField = new JFormattedTextField(dfm);
稍后我想检查 textField 中使用的格式。我检查了是否有方法textField.getFormat()
或类似的方法。没看到相关的。有没有办法知道这一点?
我有几个具有某些格式的文本字段:百分比格式、日期格式等:
DateFormat dfm= new SimpleDateFormat("yyyy-MM-dd");
textField = new JFormattedTextField(dfm);
稍后我想检查 textField 中使用的格式。我检查了是否有方法textField.getFormat()
或类似的方法。没看到相关的。有没有办法知道这一点?
正如您在源代码中看到的,您Format
的转换为JFormattedTextField.AbstractFormatterFactory
public JFormattedTextField(java.text.Format format) {
this();
setFormatterFactory(getDefaultFormatterFactory(format));
}
之后有一个 getter 可JFormattedTextField
用于检索它JFormattedTextField.AbstractFormatterFactory
。这JFormattedTextField.AbstractFormatterFactory
使您可以访问JFormattedTextField.AbstractFormatter
.
但是,您无法再访问您的实际Format
实例。根据您需要它的原因,JFormattedTextField.AbstractFormatter
可能就足够了