How to make a TextField non-responsive & non-modifyable?

It seems that some things are not as trivial using Vaadin as one would think!

E.g. I have a couple of MTexFields and I want to make one of them not editable (or rather: it should be modifyable only when certain criteria (to be defined) are met).

So I defined:
MTextField tf = new MTextField(“Foobar”);
tf.setReadOnly(true); // doesn’t seem to work…
tf.setResponsive(false); // doesn’t work either…

…but that doesn’t impress Vaadin at all.
That text field looks and appears exactly like all the others. I can placed the cursor in it, I can edit it, etc.

How can one make a TextField “un-editable” (i.e. it should be impossible to modify its contents - and ideally it should of course indicate that somehow, e.g. be grayed out or such)?

Have you tried with tf.setEnabled(false)?

HTH
Marco

Yes - still no joy.

I tried all these:
tf.setEnabled(false);
tf.setReadOnly(true);
tf.setResponsive(false);

… and I didn’t find any other method that sounds promising.
There is absolutely no visual or behavioral difference whether I set any or all of these or not.
I am starting to wonder, whether this is a bug?

Michael

Hi Michael,

that certainly sounds very odd. I haven’t played around with Viritin too much, but I just checked with a normal TextField and just tf.setEnabled(false) was enough to make it un-editable and grayed out.

-Olli

Aah - I think I found out what the issue was:
I set the above directly after creating the component (as shown in my initial append) and later add it to the list. Apparently that doesn’t work. Maybe all fields get re-enabled when adding them to a parent (in this case an MVerticalLayout)?
Now I am calling the “setEnabled(false)”

after

I have added it to its parent and now it behaves as expect, i.e. it is grayed out when being displayed.

I think this is buggy (or at least not what I would have found intuitive) but…

M.

Can you please post the full original code?
I’d like to understand better the problem

Thanks
Marco