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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:53:08+00:00 2026-06-17T06:53:08+00:00

Everywhere I see explanations on the use o FXMLLoader#setController() it’s associated with using fx:root

  • 0

Everywhere I see explanations on the use o FXMLLoader#setController() it’s associated with using fx:root and also setting a root node programmatically (both Oracle Docs and SO answers have this pattern).
Is it a requirement? Or can I create a regular FXML (probably using SceneBuilder) with some good old container and set only the controller programmatically later?

In FXML:

<BorderPane fx:id="root" prefHeight="500.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" > </Borderpane>

In some code (probably a controller):

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("fxml_example2.fxml"));
fxmlLoader.setController(this);
try {
    fxmlLoader.load();            
} catch (IOException exception) {
    throw new RuntimeException(exception);
}
  • 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-17T06:53:10+00:00Added an answer on June 17, 2026 at 6:53 am

    I don’t think it is a requirement. I’ve got this working by tweaking the Oracle tutorial code to look like this in my Application class:

    @Override
    public void start(Stage stage) throws Exception {
    
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("fxml_example.fxml"));
        fxmlLoader.setController(new ExampleController());
        Parent root = (Parent)fxmlLoader.load();
    
        stage.setTitle("FXML Welcome");
        stage.setScene(new Scene(root, 300, 275));
        stage.show();
    }
    

    As you can see I’ve set my ExampleController programatically rather than using the fx:controller="ExampleController" in the FXML and I didn’t have to set id:root anywhere to do it.

    As an aside, I quite like this approach as it mimics more closely setting the data context in MVVM with WPF and further decouples the view from the controller.

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

Sidebar

Related Questions

This should be simple: I see everywhere people use IntPtr , is there any
I see and use the :: symbols everywhere but still don't know what the
Everywhere I look, I see people explicitly using queues or run loops to do
Everywhere I see, can't find any info about it. I need that people who
I see everywhere constructions like: int? myVar = null; string test = myVar.HasValue ?
Everywhere I look, I see that MongoDB is CP. But when I dig in
I read everywhere (and see in practice) that usernames should not be changeable. When
Jumping from article to article, I can see everywhere the expression bulk loading. What
I see everywhere in iOS programming that delegate is used....I am not sure what
I see everywhere examples that super-class methods should be called by: super(SuperClass, instance).method(args) Is

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.