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 8633737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:32:34+00:00 2026-06-12T09:32:34+00:00

I use JavaFX 2.1 and I created GUI using FXML, in the controller of

  • 0

I use JavaFX 2.1 and I created GUI using FXML, in the controller of this GUI I added myTextField.requestFocus();.

But I always get the focus in the other control.

  • 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-12T09:32:35+00:00Added an answer on June 12, 2026 at 9:32 am

    At the time of initialize() controls are not yet ready to handle focus.

    You can try next trick:

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                tf.requestFocus();
            }
        });
    }
    

    For tricky complex applications (like Pavel_K has in the comments) you may want to repeat this routine several times and call method line next one:

    private void requestFocusOrDieTrying(Node node) {
        Platform.runLater(() -> {
            if (!node.isFocused()) {
                node.requestFocus();
                requestFocusOrDieTrying(node);
            }
        });
    }
    

    Note this is the undocumented approach and it may be wise to add a limit for repetitions to avoid endless loop if something changed or broke in future Java releases. Better to lose focus than a whole app. 🙂


    Example with the described threshold:

    @Override
    public void requestFocus() {
      requestFocus( getNode(), 3 );
    }
    
    private void requestFocus( final Node node, final int max ) {
      if( max > 0 ) {
        runLater(
            () -> {
              if( !node.isFocused() ) {
                node.requestFocus();
                requestFocus( node, max - 1 );
              }
            }
        );
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this easy little form in my JavaFX application. I want to use
Hello guys i have been using JavaFx scene builder to build a gui that
I'm having an issue with Threads using netbeans Swing GUI. This is my first
How to create a tile based game map in javafx 2.0? Should I use
Context I want to use JavaFx with clojure. I am aware of http://nailthatbug.net/2011/06/clojure-javafx-2-0-simple-app/ Question:
In our app, we use javax.media.JAI library to scale and improve image But sometimes
I am learning RESTful Web Services and all the tutorials use javax.ws.rs.* package. But
I have created a class that extends JLabel to use as my object moving
I created a ( JSP-based) custom EL function to use in the rendered tag.
this is the class who i use to load the images, i use the

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.