On Desktop there is a default ContextMenu
that is created and installed in TextFieldBehavior
(private API). If you don't set your own custom context menu, that will be the one used when a ContextMenuEvent
is fired (with a right click event for instance).
On mobile, both Android and iOS have a ContextMenu
as well.
On iOS, it uses a native TextField
(UITextField
). When the long press event happens, it triggers the default context menu (on my iPad I can see a small magnifying glass, and after that the context menu shows up).
On Android, the JavaFX TextField
has a custom skin, but shares the same private TextFieldBehavior
as the desktop version. The problem in this case is the missing right click event that would trigger the ContextMenuEvent
event.
That's why you have to fire manually a ContextMenuEvent
event, as it was described in this question.
Conclusion: so far, this is basically required only on Android:
TextField textField = new TextField();
addPressAndHoldHandler(textField, Duration.seconds(1), event -> {
Bounds bounds = textField.localToScreen(textField.getBoundsInLocal());
textField.fireEvent(new ContextMenuEvent(ContextMenuEvent.CONTEXT_MENU_REQUESTED,
0, 0, bounds.getMinX() + 10, bounds.getMaxY() + 10, false, null));
});