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

  • Home
  • SEARCH
  • 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 9178805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:38:23+00:00 2026-06-17T17:38:23+00:00

At the moment I have an issue with dynamically loaded FXML files during runtime.

  • 0

At the moment I have an issue with dynamically loaded FXML files during runtime. Once they are added to a Pane, they do not resize to use the full widht & height of that pane.

I use this method to load a FXML in my Pane:

public void showContentPane(String sURL){
    //1. sURL can be something like "/GUI/home/master/MasterHome.fxml"
    //2. getContentPane() returns following object: Pane pContent
    try {
        URL url = getClass().getResource(sURL);

        getContentPane().getChildren().clear();
        Node n = (Node) FXMLLoader.load(url, ResourceBundle.getBundle("src.bundles.bundle", getLocale()));

        getContentPane().getChildren().add(n);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

The FXML gets loaded and works as it should, however I notice the FXML (added as a Node in this case) is not beeing resized to use the full height and width of the content pane (if I open the FXML in preview mode with Scene Builder, it resizes perfectly). Is this a wrong approach or is there an easy way which clearly I did not find?

Thanks in advance!

  • 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-17T17:38:24+00:00Added an answer on June 17, 2026 at 5:38 pm

    I adjusted the code with the clue Andy gave me. I changed the pContent object to a AnchorPane instead of a Pane. Method that works below:

    public void showContentPane(String sURL){
        //1. sURL can be something like "/GUI/home/master/MasterHome.fxml"
        //2. getContentPane() returns following object: AnchorPane pContent
        try {
            URL url = getClass().getResource(sURL);
    
            getContentPane().getChildren().clear();
    
            //create new AnchorPane based on FXML file
            AnchorPane n = (AnchorPane) FXMLLoader.load(url, ResourceBundle.getBundle("src.bundles.bundle", getLocale()));
    
            //anchor the pane
            AnchorPane.setTopAnchor(n, 0.0);
            AnchorPane.setBottomAnchor(n, 0.0);
            AnchorPane.setLeftAnchor(n, 0.0);
            AnchorPane.setRightAnchor(n, 0.0);
    
            getContentPane().getChildren().add(n);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
    

    Hint: make sure that in your loaded FXML file you do not use fixed width or height variables.

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

Sidebar

Related Questions

I have a delete issue at the moment. We do not have permission to
Hello , I have a issue at the moment and I am not able
Having a slight Javascript issue at the moment, I am hoping to have the
I have an issue at the moment where multiple (same schema) access 2003 databases
I am writing a drowing app. At the moment i have the next issue,
So I have an issue at the moment I am trying to put tableviews
At the moment I have a very strange issue regarding locking a dictionary. I
i do not have an issue with disk space and with my web app
I am learning Python at the moment and I have hit an issue. Observe
So at the moment I have a multidimensional array string[,] items = new string[100,

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.