JLabel acts different as opposed to Servoy label

Hi All,

Just checking if it’s an expected behaviour or not. Here’s the case: I click in a field on my form, change data and then without tabbing out click on another element of the form that happens to be a JLabel bean with a mouse listener. That performs some action on the changed data.
The problem is that the data change is not captured.
If I tab out of the changed field and then click on my JLabel then everything is fine but it’s not what users will do.
I replaced my JLabel with a normal Servoy button and everything works well.

Is this some sort of a bug?
The sample solution is attached.

Cheers,
Maria

test.servoy (4.67 KB)

i didn’t check your solution, but if i read correctly then you don’t see the data yet if you click on a JLabel that has a mouse listener but you do see it when using a servoy Label
This could be because we have support to make sure that all of the ui state is correctly synced in the record before calling the events method.

Is the focus gone from the field? when you click on your label? What you can do is make sure that the focus is gone from the field and you do your action a bit later like in SwingUtilities.invokeLater() so that the servoy systems gets time to update it.

jcompagner:
i didn’t check your solution, but if i read correctly then you don’t see the data yet if you click on a JLabel that has a mouse listener but you do see it when using a servoy Label
This could be because we have support to make sure that all of the ui state is correctly synced in the record before calling the events method.

Is the focus gone from the field? when you click on your label? What you can do is make sure that the focus is gone from the field and you do your action a bit later like in SwingUtilities.invokeLater() so that the servoy systems gets time to update it.

The focus is gone from the element only after my action on JLabel is executed.
I’m not a Java programmer and I’m not sure what I’m doing buy I tried to replace my method on the button with the call to SwingUtilities.invokeLater(myMethod) which I assume will delay my method execution until the focus is lost from the element.
This way my method is only executed after the focus is lost from the element.
But again, in my method I rely on the event passed to it and I have no idea how to pass it if it’s called with .invokeLater(). What I later have as the first and only argument is a string “run”.
Could you please elaborate a bit on how you’re suggesting to use .invokeLater()? And sorry about all the confusion :oops:

Cheers,
Maria

Well, I came across another problem with JLabel today.

I am implementing drag’n’drop in my solution and it happens that in certain scenarios the drop should occur on a JLabel rather than a standard Servoy label.
However, the event in onCanDrop(event) does not recognise the element I’m hovering my mouse over. event.getElementName() returns the name of the form. So I have no way to find out whether to return true or false (because other JLabels on the same form are irrelevant, I cannot allow to drop over them).
If the bean is replaced with a Servoy label then everything works fine, so I suppose the reason is the same as before.

It would be very nice to have a workaround for this sort of problems if anyone could share a few secrets please :)

Cheers,
Maria

all this stuff all works because it is integrated into Servoy, like drag n drop support, that works because servoy labels are implementing specific interfaces and so on. (have there behavior)

If you place a label, then you have to handle the drag n drop your self in that bean, because that is what you are creating, a bean, look at the specific interfaces we have for that like IServoyAwareBean

jcompagner:
all this stuff all works because it is integrated into Servoy, like drag n drop support, that works because servoy labels are implementing specific interfaces and so on. (have there behavior)

If you place a label, then you have to handle the drag n drop your self in that bean, because that is what you are creating, a bean, look at the specific interfaces we have for that like IServoyAwareBean

I thought if I placed a bean from the list of Servoy Beans that come with the standard Servoy installation then I wouldn’t have to bother about them being different from other Servoy elements.

Cheers,
Maria

no beans are just beans they differ from servoy elements that you can also use. Why would we have both if they where the same thing?

jcompagner:
no beans are just beans they differ from servoy elements that you can also use. Why would we have both if they where the same thing?

I guess beans extend the functionality of standard Servoy elements. I wouldn’t mind if Servoy labels just had what JLabel beans have :wink: