Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX analog of Swing Action

In Swing application i can declare an Action object which allows to maintain:

  • action availability
  • accelerator key
  • what action do

and other things in single place.

Let me dive you into some details:

I'm having a scene with TreeView. In scene i have some buttons which allows to add child and remove selected item.

Additionaly i'm having an ContextMenu for TreeView with MenuItem's which does same things as a buttons.

Depending on selected item i need to enable or disable those menu items and buttons.

In Swing i can solve this easily by using Swing Action. I.e. enabling/disabling action will enable/disable all associated components.

Does JavaFX 2.2 has some analog of Swing Action?

like image 513
acc15 Avatar asked Sep 19 '13 11:09

acc15


People also ask

Does JavaFX work on Swing?

JavaFX SDK provides the JFXPanel class, which is located in the javafx. embed. swing package and enables you to embed JavaFX content into Swing applications.

Which is better JavaFX or Swing?

In short, Swing and JavaFX are both GUI toolkits for Java programs. Swing is the old standard toolkit that features a bigger library of GUI elements and mature IDE support. JavaFX is the newer standard with a smaller library, more consistent updates, and consistent MVC support.

What is JPanel JavaFX?

The JPanel is a simplest container class. It provides space in which an application can attach any other component. It inherits the JComponents class. It doesn't have title bar.

Which class must be extended to create a GUI using JavaFX?

Node is the base class that all classes involved in JavaFX GUIs must extend, including controls, shapes, and layout containers.


1 Answers

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

That being said, it should be easy enough to implement at least a workable alternative. Basically, I'd write my own Action class exposing an ObservableBooleanValue (or in your case probably a BooleanBinding) and bind the controls' disable property to it to mimic Swings enabled state. It is a bit more cumbersome, but with a few lines of utility methods you'll at least get close.

like image 111
sarcan Avatar answered Oct 04 '22 05:10

sarcan