JavaFX equivalent of Swing Action

In a Swing application, I can declare an Action object that allows me to support:

  • availability of action
  • accelerator key
  • what action

and other things in one place.

Let me tell you a few details:

I have a scene with a TreeView . In the scene, I have several buttons that allow you to add a child and delete the selected item.

Additionally, I have a ContextMenu for TreeView with a MenuItem that does the same thing as buttons.

Depending on the selected item, I need to enable or disable these menu items and buttons.

In Swing, I can easily solve this with Swing Action. That is, enabling / disabling will enable / disable all related components.

Does JavaFX 2.2 have some kind of Swing action counterpart?

+6
source share
1 answer

Short answer: None. JavaFX 2.2 does not have the equivalent of Action. There is an extension project called ControlsFX that offers action classes, but is designed to work with JavaFX 8.

At the same time, it should be simple enough to implement at least an effective alternative. Basically, I would write my own Action class, exposing an ObservableBooleanValue (or, in your case, probably BooleanBinding) and binding the disable property for it to mimic the Swings enabled state. This is a bit more cumbersome, but with a few lines of useful methods, you will at least get closer.

+2
source

Source: https://habr.com/ru/post/954159/


All Articles