By default the JavaFX TextField
has a built in ContextMenu
with 'undo', 'copy', 'cut' etc. options. The ComboBox
also has the same ContextMenu
when it is set as editable (the ComboBox
is actually part of the editor which is a TextField
).
I want to replace this ContextMenu
with a custom one but I'm having a problem with disabling the default one.
I have tried consuming the ContextMenu
and mouse click events but ComboBox
and ComboBox.getEditor()
both have a null ContextMenu
.
Am I missing something?
i hope it would help, i had the same problem with editText built in context menu and this worked for me..
EditText et; ImageView iv;
As you have already stated, a call to
GetContextMenu()
returns null (which is the big clue the default one is an implementation detail) and if you add an additionalContextMenu
it appears over the default one.Trying to replace the context menu with the following code:
Produces the following result.
Overriding the mouse clicked event isn't going to work either because you will still need to access the default Context menu via some property which doesn't seem to be possible.
I've also checked the CSS reference to see if the
ContextMenu
was target-able via one of the controls sub-structures but again this returned no results.Based on this information it looks as though the default
ContextMenu
is an implementation detail of theTextField
control (or maybe it's parent classTextInputControl
) and can't currently be changed.Update
I contacted Jonathan Giles (the tech lead at Oracle in the JavaFX UI controls team) who told me to file a bug report.
I searched the bug database and have found some existing reports (RT-23213 & RT-24823) so it appears this is a known issue. As of today the issue is still open and is considered a medium priority but apparently it will be fixed for FX 8.0.
From the bug report comments:
I have found a way to disable the default popup menu. Then you can add your own, without getting the double menu effect.
Note - I'm not adding my own menu via the menus on the combobox, I'm not sure if that will work (it might).
If you wrap the combobox in an Hbox, and add a menu to the hbox - I know that will work.