Java trying to mutate in notification

I have two swing ui forms and a module that they both look at.
Each ui adds a listener to the attribute change and updates its own textbox when the change occurs.

basiccaly - they both have to update the module and update it. Is there a way to do this without an anchor frame

This is how I do it (but I keep trying to mutate in the notification) -

In updating my textbox

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

      

still in ui - registering change

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

      

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

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

      

and I announced

public interface ValueChangeListener<T> {
     void valueChanged(T Value)
}

      

+3


source to share


1 answer


If you need to change the content of the same JTextComponent

in the listener, wrap that change (e.g. setText ()) inSwingUtilities.invokeLater()



+13


source







All Articles