User1291
User1291

Reputation: 8182

Swing -- lazy update

Does Swing have something similar to vaadin's LAZY value change mode?

As in "update on every change but after a short delay and cancel the event when the value changes again before the event has finished"?

We have a float-type text field that we bind to a property like

binder.bindProperty(MY_FOO).converted(floatToString()).to(view.myFoo, ON_KEY_TYPED);

where binder is a PresentationModelBinder and

public static BindingConverter<Float, String> floatToString() {
    return BindingConverters.<Float, String>fromModelAs(BindingConverters::toString).andFromViewAs(BindingConverters::parseFloat);
}

static <T> String toString(T anyValue) {
    return (anyValue == null) ? null : anyValue.toString();
}

static <T> String toString(Float floatValue) {
    return (floatValue == null) ? null : String.format("%.2f", floatValue);
}

Let's say you want to type 12

But it gets worse ...

Let's say you want to write 1.2

Which is a bad user experience and not what I want.

Looking at com.jgoodies.binding.binder.ValueModelBindingBuilder, I see only two options, ON_FOCUS_LOST -- which doesn't what we want -- and ON_KEY_TYPED -- which very clearly ALSO doesn't what we want.

Is there something (in Swing) that would provide us with the functionality we need or do we have to implement our own?

(And before you ask, YES, we're going to get rid of Swing in a few months.)

Upvotes: 0

Views: 59

Answers (0)

Related Questions