B4J Question Button click / action

udg

Expert
Licensed User
Longtime User
Hi all,

this came unexpected. This morning I'm working on an old system (XP, Java 1.8.0.74, B4J 4.2) and figured out something that I wasn't aware of (i.e. I didn't test it on my regular dev sys).

Using the Internal Designer to place a button on my UI and through "Tools/ Generate members", I flag both "Action" and "MouseClicked". The goal is to trap a "click" on that button from the user, indipendently if via mouse or keyboard.

What I observed is that :
- if the user uses the mouse to click on the button, both events are raised ("MouseClicked" first, "Action" last)
- if the user uses the keyboard (spacebar) to click the button, only the "Action" event is raised.

While the latter is to be ackowledged as "natural", why the former behavior?

I discovered the above because on Button_Action I placed a call to Button_MouseClicked in order to execute the same code on both circumstances but ended up with a duplicate action in case of a user's MouseClick (mouse-action-mouse sequence)!

I know how to circumvent the problem, but since I'm still building my B4J knowledge I believe is better to ask here and learn if I'm misusing the tool, having a logical fault or whatever.

Thanks
 

udg

Expert
Licensed User
Longtime User
Hi Jmon,
your suggestion works nice.
So, I've to infer that the more general _MouseClicked is "internally undertsood" as _Action so, when the latter exists for any given component it is raised as a consequence of the former?
In other words, when it exists for a component use _Action (it will catch both keyboard and mouse) otherwise use _MouseClick if you need to add any action to a componet right?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I use the Mouse_click event in imageview so that I only take action upon double-click!
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi @Cableguy ,
me too use double-clicking (on a label) for some special action. My last question referrerd to the same initial context of a component (Button, TextField..) having both _Action and _MouseClicked events.

As I understand it now, for a button, you use _Action when you need to trap indifferently the keyboard action (spacebar key on focused button) and the mouse action (click on the button). Instead, when you want to trap exclusively mouse actions (any kind of click or a double click) you use _MouseClicked event only.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Actually _Action is a quite different than mouse click. You should see it as being called when the ultimate purpose of this control has been activated.

For example, in a combobox, it is when the USER has selected an item in any way ( keyboard,mouse). It is not called when the user clicks the first time to show the dropdown. it is not called if you change the value programmatically.

Mouseclick traps any mouse click at any moment.
 
Upvote 0
Top