Hello everyone,

Let’s look at the following example. There is a MenuItem item that has a keyboard accelerator. Accordingly, the action of this MenuItem can be triggered in two cases:

1. when the Menu is shown and the user clicks or presses Enter on that menu item 2. when the Menu is NOT shown, and the action is triggered when the user presses a key combination and the accelerator is fired

It’s all very simple and straightforward. The problem arises when you need to perform a certain validation before the action of this item is executed. I asked an AI — it said to use menu.setOnShowing(...) to check whether the MenuItem should be disabled or not. However, this approach only works for case 1. So how should validation be handled for case 2?

And here it becomes obvious that code duplication should be avoided, because there can be many MenuItems, and duplicating logic for each one or creating special methods for each case looks quite messy and poorly designed.

Maybe someone from the JavaFX developers can clarify how this is actually intended to work?

Best regards, Pavel

Reply via email to