I have noticed that there is no JavaFX 8 class similar to QAction in Qt which is a centralized user action which can be triggered by many GUI-components. I have myself used it when having the same action in a menu and a toolbar. The action class allows the programmer to handle action events in a single place. Qt's QAction class can also contain an icon for the action such that the widget which is associated with the action can choose whether to show the icon, the text or both.
Many things in JavaFX extend Labeled, which allow you to specify, text or a graphic (icon) display, or both (via the setContentDisplay API). MenuItems also have the ability to set graphics. Though graphics are most often just an ImageView, they can be any kind of node, so you could make the graphic a more complex widget or an animation or something like that if you wished.
Stefan K Larsson
Joined: Jul 09, 2014
I have already tried out the accelerators for menus and such. The biggest advantage I find when using QAction is to be able to add a menu item automatically by just adding the action and everything else is resolved. It can be used as the sole argument to a tool bar button constructor to get a button which is bound the the given action. The actions can be stored in a controller which is totally ignorant about who is triggering the action. Just a convenience.
John Damien Smith
Joined: Jan 26, 2012
If you are keen and have the time, you could develop an action system as either a stand-alone open source project or as part of ControlsFX.
The ControlsFX developers include guys like Hendrick Ebbers (author of Mastering JavaFX 8 Controls) and Jonathan Giles (main Controls API maintainer for JavaFX), so they could provide some assistance. Developing for ControlsFX allows for a quicker development cycle then the main JavaFX branch, then, once the API is proven, it could be ported into JavaFX proper. I think it is the intention to add such an API to JavaFX based upon comments on https://javafx-jira.kenai.com/browse/RT-30749 (though such comments cannot be treated as commitments).
Stefan K Larsson
Joined: Jul 09, 2014
Thanks for pointing me to the ControlsFX project.
I found the Action class which seems to be just about what I am looking for.
Looking closer att the source code I believe that the functionality is there already although the Action API is separated from the rest through ActionUtils. What is needed is to implement those functions into all the controls of JavaFX such that the constructors can consume the Action class and ditch the ActionUtil class. I could of course create such a merge just to learn my way around the code better, but I am not sure who would be interested in the resulting code. It would not fit into ControlsFX since it needs to involve the JavaFX controls as well.
Maybe I should address these questions directly to the ControlsFX mailing list instead.
Adding Action support for FXML might be a design challenge though...
> Maybe I should address these questions directly to the ControlsFX mailing list instead
Yes, that and the openjfx development mailing list are good places for these discussions and questions.
> Adding Action support for FXML might be a design challenge
FXML is pretty generic and has already has a simple, extensible architecture. It works based upon reflection, so if you just add an action property to the root control classes which accept actions (e.g. buttons, toolbars, menu items) and define a single builder property for the action class, then you can define an FXML element for an action on a control or menu item. So that part should not be very difficult I think. Probably you would also want to add some UI to SceneBuilder provide a bit of custom UI for action attachment, that part would be a bit more work.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com