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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:23:31+00:00 2026-06-08T17:23:31+00:00

Problem I want to add custom made panels, built via javafx scene builder, to

  • 0

Problem
I want to add custom made panels, built via javafx scene builder, to a gridpane at runtime. My custom made panel exsits of buttons, labels and so on.

My Attempt
I tried to extend from pane…

public class Celli extends Pane{
    public Celli() throws IOException{
        Parent root = FXMLLoader.load(getClass().getResource("Cell.fxml"));
        this.getChildren().add(root);     
    }
}

… and then use this panel in the adding method of the conroller

@FXML
private void textChange(KeyEvent event) {
    GridPane g = new GridPane();
        for (int i=0 : i<100; i++){
                g.getChildren().add(new Celli());
        }
    }
}

It works, but it performs very very poor.

What I am looking for
Is there a way to design panels via javafx scene builder (and as a result having this panels in fxml) and then add it to a gridpane at runtime without make use of this fxmlloader for each instance. I think it performs poor because of the fxml loader. When I add a standard button e.g. whitout fxml it is very much faster.

  • 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-08T17:23:33+00:00Added an answer on June 8, 2026 at 5:23 pm

    Short answer: No, it is not (as of JavaFX 2.x and 8.0). It may be in a future version (JFX >8)

    Long answer:
    The FXMLLoader is currently not designed to perform as a template provider that instantiates the same item over and over again. Rather it is meant to be a one-time-loader for large GUIs (or to serialize them).

    The performance is poor because depending on the FXML file, on each call to load(), the FXMLLoader has to look up the classes and its properties via reflection. That means:

    1. For each import statement, try to load each class until the class could successfully be loaded.
    2. For each class, create a BeanAdapter that looks up all properties this class has and tries to apply the given parameters to the property.
    3. The application of the parameters to the properties is done via reflection again.

    There is also currently no improvement for subsequent calls to load() to the same FXML file done in the code. This means: no caching of found classes, no caching of BeanAdapters and so on.

    There is a workaround for the performance of step 1, though, by setting a custom classloader to the FXMLLoader instance:

    import java.io.IOException; 
    import java.net.URL; 
    import java.util.Enumeration; 
    import java.util.HashMap; 
    import java.util.Map; 
    
    public class MyClassLoader extends ClassLoader{ 
      private final Map<String, Class> classes = new HashMap<String, Class>(); 
      private final ClassLoader parent; 
    
      public MyClassLoader(ClassLoader parent) { 
        this.parent = parent; 
      } 
    
      @Override 
      public Class<?> loadClass(String name) throws ClassNotFoundException { 
        Class<?> c = findClass(name); 
        if ( c == null ) { 
          throw new ClassNotFoundException( name ); 
        } 
        return c; 
      } 
    
      @Override 
      protected Class<?> findClass( String className ) throws ClassNotFoundException { 
    // System.out.print("try to load " + className); 
        if (classes.containsKey(className)) { 
          Class<?> result = classes.get(className); 
          return result; 
        } else { 
          try { 
            Class<?> result = parent.loadClass(className); 
    // System.out.println(" -> success!"); 
            classes.put(className, result); 
            return result; 
          } catch (ClassNotFoundException ignore) { 
    // System.out.println(); 
            classes.put(className, null); 
            return null; 
          } 
        } 
      } 
    
      // ========= delegating methods ============= 
      @Override 
      public URL getResource( String name ) { 
        return parent.getResource(name); 
      } 
    
      @Override 
      public Enumeration<URL> getResources( String name ) throws IOException { 
        return parent.getResources(name); 
      } 
    
      @Override 
      public String toString() { 
        return parent.toString(); 
      } 
    
      @Override 
      public void setDefaultAssertionStatus(boolean enabled) { 
        parent.setDefaultAssertionStatus(enabled); 
      } 
    
      @Override 
      public void setPackageAssertionStatus(String packageName, boolean enabled) { 
        parent.setPackageAssertionStatus(packageName, enabled); 
      } 
    
      @Override 
      public void setClassAssertionStatus(String className, boolean enabled) { 
        parent.setClassAssertionStatus(className, enabled); 
      } 
    
      @Override 
      public void clearAssertionStatus() { 
        parent.clearAssertionStatus(); 
      } 
    }
    

    Usage:

    public static ClassLoader cachingClassLoader = new MyClassLoader(FXMLLoader.getDefaultClassLoader()); 
    
    FXMLLoader loader = new FXMLLoader(resource); 
    loader.setClassLoader(cachingClassLoader); 
    

    This significantly speeds up the performance. However, there is no workaround for step 2, so this might still be a problem.

    However, there are already feature requests in the official JavaFX jira for this. It would be nice of you to support this requests.

    Links:

    • FXMLLoader should be able to cache imports and properties between to load() calls:
      https://bugs.openjdk.java.net/browse/JDK-8090848

    • add setAdapterFactory() to the FXMLLoader:
      https://bugs.openjdk.java.net/browse/JDK-8102624

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

Sidebar

Related Questions

I have the following problem: I want to add a custom view (custom_view.xml and
Problem: I want to add headers in the middle of a gridview databind. I
I'm experiencing this problem: I want to add the Google Maps API to my
I have problem, when I want add Node to my GUI from other Thread.
I have a little problem, I have an array and I want to add
I've got some tabs. http://img196.imageshack.us/img196/7167/tabs.gif And I want to add a rollover effect. Problem
I'm having a serious problem with custom post types in Wordpress. I made a
I want to add a custom table to my iPhone app, that should look
I want to create an custom control (descendant of TRichEdit). I simply want add
I want to add custom (compound and read-only) attributes to my stored procedure results

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.