0

我有一个将我的 JTextField 绑定到 JGoodies 中的 bean 的方法

public static JTextField bindDoubleTextField(PresentationModel<?> adapter, String 

propertyName, boolean useBuffer)
{
   ValueModel valueModel = getValueModel(adapter, propertyName, useBuffer);
   DecimalFormat decimalFormat = new DecimalFormat("0.######");
   decimalFormat.setGroupingUsed(false);
   JTextField textField = BasicComponentFactory.createFormattedTextField(valueModel, decimalFormat);

   return textField;
}

稍后在代码中,我将 propertyChangeListener 添加到 ValueModel,但它仅在我失去对 JTextField 的焦点时接收事件。是否可以在我输入时接收这些事件?我希望能够根据值是否与其原始值不同来设置 JTextField 的背景颜色。我不想在键入时提交值,我只想检测该值是否与上次提交的值不同。

4

2 回答 2

1

是否可以在我输入时接收这些事件?

请参阅实现文档过滤器或可能的如何编写文档侦听器

于 2013-03-04T19:05:45.293 回答
0

使用 BasicComponentFactory.createTextField(ValueModel,boolean) 可能会更好。这允许您为第二个参数传递 false 并且提交将在您键入时发生。但是您必须自己进行格式化和验证,或者使用 JGoodies 验证 API。

JGoodies 将与您可能使用的任何文档或其他格式化程序发生冲突。

于 2013-04-28T00:49:12.683 回答