java attempt to mutate in notification

Go To StackoverFlow.com

3

I have two swing ui forms and a module that they both look at.
Each ui is adding a listener to the change of an attribute and update its own textfield when a change occurs.

basiccaly - they both should update the module and be update from it. Is there a way simple to do it whithout a binding framework

Here is how I do it (but I keep getting attempt to mutate in notification ) -

On the update of my textField

 myTextField.getDocument().addDocumentListener(new TFDocumentListener() {
            protected void userChangedTF() {
                Float value = myTextField.getValue();
                if (value != null) {
                    myObj.setMyAttribute(value);
                }
            }
        });

still in the ui - registering the change

        myObj.addMyAttributeChangedListener(new ValueChangeListener<Float>() {
            @Override public void valueChanged(Float value) {
                if (!myTextField.isFocusOwner()) {
                    myTextField.setValueIn(value);
                }
            }
        });

in the module - when setMyAttribute occurs - it calls this function

private void notifyIntervalChanged(float newValue) {
    for (ValueChangeListener valueChangeListener : intervalChangedListenersList) {
        valueChangeListener.valueChanged(newValue);
    }
}

and I declared

public interface ValueChangeListener<T> {
     void valueChanged(T Value)
}
2012-04-04 06:28
by Bick
ValueChangeListener is listener for JSF ??? isn't it, please edit your question with SSCC - mKorbel 2012-04-04 06:40
JSF? Swing. fixed anyway. thanks - Bick 2012-04-04 06:49


13

If you need to change content of the same JTextComponent in the listener wrap the change (e.g. setText()) in the SwingUtilities.invokeLater()

2012-04-04 06:49
by StanislavL
Ads