Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9112761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:48:45+00:00 2026-06-17T03:48:45+00:00

Based on the JavaFX EventHandler<T> it is quite simple to create a listener for

  • 0

Based on the JavaFX EventHandler<T> it is quite simple to create a listener for a specific action. For the sake of argument, code would look as such :

btn.setOnAction(new EventHandler<ActionEvent>() {
    public void handle(ActionEvent event) {
        System.out.println("Hello World");
    }
});

Now let’s say I wanted to have more complex things be processed on this event (let’s say it takes me 50-100 lines of code). I could use the same approach and have all this code within my handler, and thus in my controller.

If I wanted to have this slightly cleaner looking I could implement the EventHandler<T> interface. This would look as such :

public class LoginHandler implements EventHandler<ActionEvent> {

    // list of parameters passed

    public LoginHandler(ResourceBundle resources) {
        //Resources along with other paramters I need to access
        this.resources = resources;
    }

    @Override
    public void handle(ActionEvent event) {
        //...Logic goes here
        System.out.println("doing my logic here - 50 to 100 lines");
        ((Node)(event.getSource())).getScene().getWindow().hide();
    }
}

Such an approach works, but I do have to pass as a parameter all the objects (wether that be a button, label, textbox, etc) and ResourceBundle (if trying to internationalize my app).

Is there any way to access all this information? Bascially access the controller from the EventHandler? Or is the best practice to leave everything in the controllers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:48:46+00:00Added an answer on June 17, 2026 at 3:48 am

    In my opinion, if the logic to be done in the handle method is related to view (ie the controls in FXML) it should be kept in the controller. No one other than controller have to know the FXML structure. If you are going to do a general and common logic in the extended eventHandler, in addtion to other parameters, also pass the controller instance to this eventHandler. Then delegate view related jobs to the controller, like controller.updateView(params) for example. Those controllers can also implement a common interface that has the updateView(params) method signature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to create a tile based game map in javafx 2.0? Should I use
My application is Swing-based. I would like to introduce JavaFX and configure it to
based on the volume knob from this example, http://fxexperience.com/2012/01/fun-javafx-2-0-audio-player/ How would you make a
I have just explore javaFX. I am now programming modul based application by netBeans
Is there an event that gets fired when somebody closes a desktop-based Java/JavaFx application
I am new to JavaFx technology, I would like to know whether I can
I post new question based on this previously code posted here ( Filter users
I'm new to Java and JavaFX I have php,javascript,HTML experience... I'm trying to create
I'm developing a simple webapp based on Spring framework. I have these two files
I want to make an application in JavaFX-2 based on two pages as main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.