Staale
Staale

Reputation: 28008

JTextField doesn't seem to fire PropertyChangeEvent

I am trying to create a swing form where the text fields are connected to a bean using the bensbindings framework. I have set this up in the Netbeans matisse editor. However, changing the content of a JTextField doesn't seem to update the bean.

Trying just a simple case of a JTextField with a PropertyChangeListener, there never occurs any property change events as text is input. When are these events fired? Or is it only possible to bind from a bean to the text field and not the other way?

What is the prefered way of getting the content of a JTextField to update a Bean? IS it doing it manually when a button is pressed?

I am pretty new to swing, and I want to learn how to use beansbindings and the Better Swing Application Framework to build an application.

Upvotes: 2

Views: 3266

Answers (2)

Uhlen
Uhlen

Reputation: 1778

As specified by JTextComponent#setText:

Note that text is not a bound property, so no PropertyChangeEvent is fired when it changes. To listen for changes to the text, use DocumentListener.

Upvotes: 3

StanislavL
StanislavL

Reputation: 57421

Try to add a DocumentListener to the JTextField's document. The listener is invoked on type/remove, cut/paste.

Upvotes: 1

Related Questions