File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JavaFX and the fly likes Moving from SymAction in Java.awt to something in JavaFX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Moving from SymAction in Java.awt to something in JavaFX" Watch "Moving from SymAction in Java.awt to something in JavaFX" New topic

Moving from SymAction in Java.awt to something in JavaFX

Jim Anderson

Joined: Apr 19, 2013
Posts: 15

How do I convert "Java.awt" code that uses SymAction into JavaFX format?

After I define three Buttons, here's my working "Java.awt" code:

SymAction lSymAction = new SymAction();

class SymAction implements java.awt.event.ActionListener{
public void actionPerformed(java.awt.event.ActionEvent event){
Object object = event.getSource();
if (object == IterationButton){
if (object == OneIterButton){
else if (object == SaveImageButton){

void OneIterButton_ActionPerformed(java.awt.event.ActionEvent event){

void IterationButton_ActionPerformed(java.awt.event.ActionEvent event){

void SaveImageButton_ActionPerformed(java.awt.event.ActionEvent event){
Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

Hi Jim,
JavaFX has a Button control that you can use to build buttons and add listeners to it. Do click on the link to know more.

To know more about building a JavaFX application, you can start here

Volodymyr Lysenko
Ranch Hand

Joined: Mar 29, 2012
Posts: 511

Yes, but does JavaFX provide substitution for java.awt.Action class?

It seems that not.

True person is moral, false is right!
John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 227
On RT-30749 Overload Button type constructors to allow an ActionEvent to be set on the button a developer offered the following comment in relation to java.awt.Action style functionality in JavaFX.
Whilst a good idea, I would like to hold off on this feature until we think through add an Action API into JavaFX. At that point it may be that ActionEvent shouldn't be passed into the constructor, but Action objects (which include not just the event handler but all the appropriate state (text, tooltip, graphic, selected, etc).

So it would appear that the JavaFX developers have considered adding such functionality to JavaFX, but it is not present for Java 8 (which is the target version for which the above comment was made). The functionality is also not directly present in any 3rd party libraries that I am aware of. If you want to use such functionality in your application, you will need to implement it yourself.
Jim Anderson

Joined: Apr 19, 2013
Posts: 15

Ranganathan Kaliyur Mannar: Thanks for your comment. I was aware of the article by Alla Redko. She suggests that the "add Button method" can be used to add a large # of buttons & associated actions. In practice, I find that only two or fewer buttons can be used. If one tries to add (say) five buttons, the buttons look ok, but the associated actions get fouled up. This led to my "SymAction" question. As others have noted, there's no analog of the awt.ActionEvent protocol in javafx.

I think that one should be working with the "ToggleButton" function, letting each "toggle" produce a specific action. Any thoughts?

Jim Anderson
I agree. Here's the link:
subject: Moving from SymAction in Java.awt to something in JavaFX
It's not a secret anymore!