Custom Components in Scenebuilder 2.0

2019-05-17 19:34发布

问题:

In Scenebuilder 1.1, you could import an entire custom component as a whole.

In 2.0, however, it is importing the component as separate pieces (Container and nodes). Since my custom component relies on being unified to work with its controller and IDs, this breaks it.

Is there anything I can do as of yet? I'd really like to be able to use Java 8 and Scenebuilder 2.0 for its DatePicker. If a full stable release is right around the corner, perhaps I can wait. I'd preferably want to avoid hacky solutions.

Any ideas?

回答1:

I have only found one way to deal with this kind of back-compatibility: building my own scenebuilder.

It is officially open source so you can check it out with mercurial on bitbucket for instance.

Then you build it and modify it to put all your custom components and dependencies in the same classpath for one unique classloader.

Check the class named FXOMLLoader, it is where the classloader is used, my fix was to explicitly only use one classloader for all components and adding a few repertories with my deps inside to the classpath for it to work.

I have used Jar Class Loader library to do so, and it works pretty well. This is pretty hacky though.