How can I force a mouseClicked
action on a numeric textfield component via script?
e.g. to simulate an actionPerformed
event for a button I would call:
button.doClick()
Reason is, touchscreen mode is enabled and I want to force the touchscreen numeric keypad to open to edit the component value, but via script…
This post looks like it’s on the money, but it seems that the getActionListeners
method has been made private… Also I wouldn’t know how to create the ActionEvent
to pass into it.
//JAVA CODE
// Does not appear in the UI
for(ActionListener a: mybutton.getActionListeners()) {
a.actionPerformed(yourActionEvent);
}
You might need to use Java’s Robot input simulation kit.
1 Like
I think there’s some “getFocus” function that may do the same. I think I saw something similar in my app, Ill see if it’s applicable.
Edit: Ok so we do stuff like this to give focus to a component upon opening a form I think it may work for you.
component = system.gui.getParentWindow(event).getComponentForPath('Root Container.txtCustomerName')
component.requestFocusInWindow()
Hmm, well I don’t really like it, but using Robot does work. It feels a bit clunky though, and backfires if the mouse is moved.
FYI: requesting focus only moves the focus to the component, it doesn’t fire off any click events. I was doing this already, but then when I tried it with touchscreen enabled, it then required an extra tap to open up the keypad.
#click on the textfield to launch the numeric keypad to stop the user having to click on the component twice
def clickAgain():
from java.awt import Robot
from java.awt.event import InputEvent
r = Robot()
r.mousePress(InputEvent.BUTTON1_MASK)
r.mouseRelease(InputEvent.BUTTON1_MASK)
#delay 500 so that a double-click isn't registered
system.util.invokeLater(clickAgain,500)