0

I have a method which binds my JTextField to a bean in JGoodies

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;
}

Later in the code I add a propertyChangeListener to the ValueModel, but it only receives the event when I lose focus to the JTextField. Is it possible to receive those events as I type? I want to be able to set the background color of the JTextField depending on whether the value is different from its original value. I do not want the value committed as I type, I just want to detect whether the value is different from the last committed value.

smuggledPancakes
  • 9,881
  • 20
  • 74
  • 113

2 Answers2

1

Is it possible to receive those events as I type?

See Implementing a Document Filter or possibly How to Write a Document Listener.

camickr
  • 321,443
  • 19
  • 166
  • 288
0

You might be better off using BasicComponentFactory.createTextField(ValueModel,boolean). That allows you to pass false for the second argument and commits will happen as you type. But you'd have to do the formatting and validation yourself, or use JGoodies validation API.

JGoodies will conflict with any Documents or other formatters you may use.